Skip to content

Commit

Permalink
Simplify ArgumentBuilder and remove unused parameters
Browse files Browse the repository at this point in the history
Refactored the ArgumentBuilder class to reduce complexity by consolidating constructors and eliminating redundant parameters. Removed the obsolete ExecuteIn method that utilized these parameters from GitVersionHelper. Updated the test case to align with the new method signature and ensure functionality remains intact.
  • Loading branch information
arturcic committed Dec 4, 2024
1 parent 498fd06 commit 4ef6871
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 63 deletions.
53 changes: 4 additions & 49 deletions src/GitVersion.App.Tests/Helpers/ArgumentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,11 @@

namespace GitVersion.App.Tests;

public class ArgumentBuilder
public class ArgumentBuilder(string? workingDirectory, string? additionalArguments, string? logFile)
{
public ArgumentBuilder(string? workingDirectory) => this.WorkingDirectory = workingDirectory;
public string? WorkingDirectory { get; } = workingDirectory;

public ArgumentBuilder(string? workingDirectory, string? exec, string? execArgs, string? projectFile, string? projectArgs, string? logFile)
{
this.WorkingDirectory = workingDirectory;
this.exec = exec;
this.execArgs = execArgs;
this.projectFile = projectFile;
this.projectArgs = projectArgs;
this.LogFile = logFile;
}

public ArgumentBuilder(string? workingDirectory, string? additionalArguments, string? logFile)
{
this.WorkingDirectory = workingDirectory;
this.additionalArguments = additionalArguments;
this.LogFile = logFile;
}

public string? WorkingDirectory { get; }

public string? LogFile { get; }
public string? LogFile { get; } = logFile;

public override string ToString()
{
Expand All @@ -36,39 +17,13 @@ public override string ToString()
arguments.Append(" /targetpath \"").Append(this.WorkingDirectory).Append('\"');
}

if (!this.exec.IsNullOrWhiteSpace())
{
arguments.Append(" /exec \"").Append(this.exec).Append('\"');
}

if (!this.execArgs.IsNullOrWhiteSpace())
{
arguments.Append(" /execArgs \"").Append(this.execArgs).Append('\"');
}

if (!this.projectFile.IsNullOrWhiteSpace())
{
arguments.Append(" /proj \"").Append(this.projectFile).Append('\"');
}

if (!this.projectArgs.IsNullOrWhiteSpace())
{
arguments.Append(" /projargs \"").Append(this.projectArgs).Append('\"');
}

if (!this.LogFile.IsNullOrWhiteSpace())
{
arguments.Append(" /l \"").Append(this.LogFile).Append('\"');
}

arguments.Append(this.additionalArguments);
arguments.Append(additionalArguments);

return arguments.ToString();
}

private readonly string? additionalArguments;
private readonly string? exec;
private readonly string? execArgs;
private readonly string? projectArgs;
private readonly string? projectFile;
}
14 changes: 0 additions & 14 deletions src/GitVersion.App.Tests/Helpers/GitVersionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,6 @@ namespace GitVersion.App.Tests;

public static class GitVersionHelper
{
public static ExecutionResults ExecuteIn(string? workingDirectory,
string? exec = null,
string? execArgs = null,
string? projectFile = null,
string? projectArgs = null,
bool logToFile = true,
params KeyValuePair<string, string?>[] environments
)
{
var logFile = logToFile ? PathHelper.Combine(workingDirectory, "log.txt") : null;
var args = new ArgumentBuilder(workingDirectory, exec, execArgs, projectFile, projectArgs, logFile);
return ExecuteIn(args, environments);
}

public static ExecutionResults ExecuteIn(
string? workingDirectory,
string? arguments,
Expand Down

0 comments on commit 4ef6871

Please sign in to comment.