Skip to content

Commit

Permalink
Fix argument formatting for boolean values.
Browse files Browse the repository at this point in the history
  • Loading branch information
matkoch committed Mar 4, 2018
1 parent 2684e44 commit 26442ee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 5 additions & 2 deletions source/Nuke.Common.Tests/SettingsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,17 @@ public void TestMSBuild()
.SetProjectFile(projectFile)
.SetTargetPlatform(MSBuildTargetPlatform.MSIL)
.SetConfiguration("Release")
.DisableNodeReuse()
.EnableNoLogo(),
$"{projectFile} /nologo /p:Platform=AnyCPU /p:Configuration=Release");
$"{projectFile} /nodeReuse:False /nologo /p:Platform=AnyCPU /p:Configuration=Release");

Assert<MSBuildSettings>(x => x
.SetProjectFile(solutionFile)
.SetTargetPlatform(MSBuildTargetPlatform.MSIL)
.EnableNodeReuse()
.DisableNoLogo()
.ToggleRunCodeAnalysis(),
$"{solutionFile} /p:Platform=\"Any CPU\" /p:RunCodeAnalysis=True");
$"{solutionFile} /nodeReuse:True /p:Platform=\"Any CPU\" /p:RunCodeAnalysis=True");
}

[Fact]
Expand Down
9 changes: 6 additions & 3 deletions source/Nuke.Core/Tooling/Arguments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public interface IArguments
string RenderForOutput();
}

// TODO: extract {value} and {key} into constants
public sealed class Arguments : IArguments
{
private const string c_hiddenString = "[hidden]";
Expand All @@ -26,15 +27,17 @@ public sealed class Arguments : IArguments
private readonly List<string> _secrets = new List<string>();
private readonly LookupTable<string, string> _arguments = new LookupTable<string, string>(StringComparer.OrdinalIgnoreCase);

public Arguments Add(string argument, bool? condition = true)
public Arguments Add(string argumentFormat, bool? condition = true)
{
return Add(argument, condition.HasValue && condition.Value ? new object() : null);
return condition.HasValue && (condition.Value || argumentFormat.Contains("{value}"))
? Add(argumentFormat, (object) condition.Value)
: this;
}

public Arguments Add<T>(string argumentFormat, T? value, char? disallowed = null, bool secret = false)
where T : struct
{
return Add(argumentFormat, value.HasValue ? (object) value.Value : null, disallowed, secret);
return value.HasValue ? Add(argumentFormat, value.Value, disallowed, secret) : this;
}

public Arguments Add(string argumentFormat, [CanBeNull] object value, char? disallowed = null, bool secret = false)
Expand Down

0 comments on commit 26442ee

Please sign in to comment.