Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,22 @@ public void Should_Add_Additional_Arguments()
var result = fixture.Run();

// Then
Assert.Equal("project convert \"/Working/cake.cs\" --delete-source --dry-run --force --interactive --output \"/Working/cake\" --verbosity diagnostic", result.Args);
Assert.Equal("project convert \"/Working/cake.cs\" --delete-source --dry-run --force --interactive true --output \"/Working/cake\" --verbosity diagnostic", result.Args);
}

[Fact]
public void Should_Add_Interactive_False()
{
// Given
var fixture = new DotNetProjectConverterFixture();
fixture.File = "cake.cs";
fixture.Settings.Interactive = false;

// When
var result = fixture.Run();

// Then
Assert.Equal("project convert \"/Working/cake.cs\" --interactive false", result.Args);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,24 @@ public void Should_Add_Additional_Arguments()
var result = fixture.Run();

// Then
var expected = "add \"ToDo.csproj\" reference \"/Working/lib1.csproj\" --framework net10.0 --interactive --verbosity diagnostic";
var expected = "add \"ToDo.csproj\" reference \"/Working/lib1.csproj\" --framework net10.0 --interactive true --verbosity diagnostic";
Assert.Equal(expected, result.Args);
}

[Fact]
public void Should_Add_Interactive_False()
{
// Given
var fixture = new DotNetReferenceAdderFixture();
fixture.ProjectReferences = new[] { (FilePath)"./lib1.csproj" };
fixture.Project = "ToDo.csproj";
fixture.Settings.Interactive = false;

// When
var result = fixture.Run();

// Then
Assert.Equal("add \"ToDo.csproj\" reference \"/Working/lib1.csproj\" --interactive false", result.Args);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,21 @@ public void Should_Add_Host_Arguments()
Assert.Equal("--diagnostics restore", result.Args);
}

[Fact]
public void Should_Add_Interactive()
[Theory]
[InlineData(true, "restore --interactive true")]
[InlineData(false, "restore --interactive false")]
[InlineData(null, "restore")]
public void Should_Add_Interactive(bool? interactive, string expected)
{
// Given
var fixture = new DotNetRestorerFixture();
fixture.Settings.Interactive = true;
fixture.Settings.Interactive = interactive;

// When
var result = fixture.Run();

// Then
Assert.Equal($@"restore --interactive", result.Args);
Assert.Equal(expected, result.Args);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,28 @@ public void DotNetToolInstall_WithInstallationScope_RendersSingleScopeFlag(DotNe
Assert.Equal($"\"tool\" install dotnetsay {expectedScopeArgument}", result.Args);
}

[Theory]
[InlineData(true, "\"tool\" install dotnetsay --global --create-manifest-if-needed true")]
[InlineData(false, "\"tool\" install dotnetsay --global --create-manifest-if-needed false")]
[InlineData(null, "\"tool\" install dotnetsay --global")]
public void DotNetToolInstall_WithCreateManifestIfNeeded_RendersExplicitValue(bool? createManifestIfNeeded, string expected)
{
// Given
var fixture = new DotNetToolCommandFixture
{
Invocation = DotNetToolCommandInvocation.InstallFull,
CommandArgument = "dotnetsay"
};
fixture.InstallSettings.InstallationScope = DotNetToolInstallationScope.Global;
fixture.InstallSettings.CreateManifestIfNeeded = createManifestIfNeeded;

// When
var result = fixture.Run();

// Then
Assert.Equal(expected, result.Args);
}

[Fact]
public void DotNetToolExecute_WithDefaultSettings_RendersExpectedCommand()
{
Expand Down Expand Up @@ -283,7 +305,7 @@ public void DotNetToolCommands_RenderCommandSpecificSettings()
var result = fixture.Run();

// Then
var expected = "\"tool\" install dotnetsay --tool-path \"/Working/tools\" --version \"1.2.3\" --configfile \"/Working/nuget.config\" --source \"https://example.com/source\" --add-source \"https://example.com/add-source\" --prerelease --tool-manifest \"/Working/.config/dotnet-tools.json\" --framework \"net10.0\" --disable-parallel --ignore-failed-sources --no-http-cache --interactive --allow-downgrade --arch \"x64\" --create-manifest-if-needed --allow-roll-forward";
var expected = "\"tool\" install dotnetsay --tool-path \"/Working/tools\" --version \"1.2.3\" --configfile \"/Working/nuget.config\" --source \"https://example.com/source\" --add-source \"https://example.com/add-source\" --prerelease --tool-manifest \"/Working/.config/dotnet-tools.json\" --framework \"net10.0\" --disable-parallel --ignore-failed-sources --no-http-cache --interactive --allow-downgrade --arch \"x64\" --create-manifest-if-needed true --allow-roll-forward";
Assert.Equal(expected, result.Args);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,24 @@ public void Should_Add_Additional_Arguments()
var result = fixture.Run();

// Then
var expected = "workload install maui --configfile \"/Working/nuget.config\" --disable-parallel --ignore-failed-sources --include-previews --interactive --no-cache --skip-manifest-update";
var expected = "workload install maui --configfile \"/Working/nuget.config\" --disable-parallel --ignore-failed-sources --include-previews --interactive true --no-cache --skip-manifest-update";
expected += " --source \"http://www.nuget.org/api/v2/package\" --source \"http://www.symbolserver.org/\" --temp-dir \"/Working/src/project\" --verbosity diagnostic";
Assert.Equal(expected, result.Args);
}

[Fact]
public void Should_Add_Interactive_False()
{
// Given
var fixture = new DotNetWorkloadInstallerFixture();
fixture.WorkloadIds = new string[] { "maui" };
fixture.Settings.Interactive = false;

// When
var result = fixture.Run();

// Then
Assert.Equal("workload install maui --interactive false", result.Args);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,25 @@ public void Should_Add_Additional_Arguments()
var result = fixture.Run();

// Then
var expected = "workload restore \"./src/*\" --configfile \"/Working/nuget.config\" --disable-parallel --ignore-failed-sources --include-previews --interactive --no-cache --skip-manifest-update --source \"http://www.nuget.org/api/v2/package\" --source \"http://www.symbolserver.org/\" --temp-dir \"/Working/src/project\" --verbosity diagnostic";
var expected = "workload restore \"./src/*\" --configfile \"/Working/nuget.config\" --disable-parallel --ignore-failed-sources --include-previews --interactive true --no-cache --skip-manifest-update --source \"http://www.nuget.org/api/v2/package\" --source \"http://www.symbolserver.org/\" --temp-dir \"/Working/src/project\" --verbosity diagnostic";
Assert.Equal(expected, result.Args);
}

[Fact]
public void Should_Add_Interactive_False()
{
// Given
var fixture = new DotNetWorkloadRestorerFixture();
fixture.Project = "./src/*";
fixture.Settings.Interactive = false;

// When
var result = fixture.Run();

// Then
Assert.Equal("workload restore \"./src/*\" --interactive false", result.Args);
}

[Theory]
[InlineData("./src/*", "workload restore \"./src/*\"")]
[InlineData("./src/cake build/", "workload restore \"./src/cake build/\"")]
Expand Down
2 changes: 1 addition & 1 deletion src/Cake.Common/Tools/DotNet/DotNetAliases.Tool.Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private static void AppendToolInstallSettings(ProcessArgumentBuilder builder, Do
AppendRestoreSettings(builder, settings.DisableParallel, settings.IgnoreFailedSources, settings.NoHttpCache, settings.Interactive);
AppendSwitch(builder, "--allow-downgrade", settings.AllowDowngrade);
AppendString(builder, "--arch", settings.Architecture);
AppendSwitch(builder, "--create-manifest-if-needed", settings.CreateManifestIfNeeded);
builder.AppendSwitch("--create-manifest-if-needed", settings.CreateManifestIfNeeded);
AppendSwitch(builder, "--allow-roll-forward", settings.AllowRollForward);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ public sealed class DotNetProjectConvertSettings : DotNetSettings
/// <summary>
/// Gets or sets a value indicating whether to allow the command to stop and wait for user input or action.
/// For example, to complete authentication.
/// When <c>null</c>, the .NET CLI default is used.
/// </summary>
public bool Interactive { get; set; }
public bool? Interactive { get; set; }

/// <summary>
/// Gets or sets the output directory for the converted project.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ private ProcessArgumentBuilder GetArguments(FilePath file, DotNetProjectConvertS
builder.Append("--force");
}

if (settings.Interactive)
{
builder.Append("--interactive");
}
builder.AppendSwitch("--interactive", settings.Interactive);

if (settings.Output != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public sealed class DotNetReferenceAddSettings : DotNetSettings
/// <summary>
/// Gets or sets a value indicating whether to allow the command to stop and wait for user input or action.
/// For example, to complete authentication. Available since .NET Core 3.0 SDK.
/// When <c>null</c>, the .NET CLI default is used.
/// </summary>
public bool Interactive { get; set; }
public bool? Interactive { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,7 @@ private ProcessArgumentBuilder GetArguments(string project, IEnumerable<FilePath
}

// Interactive
if (settings.Interactive)
{
builder.Append("--interactive");
}
builder.AppendSwitch("--interactive", settings.Interactive);

return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ public class DotNetRestoreSettings : DotNetSettings

/// <summary>
/// Gets or sets a value indicating whether to stop and wait for user input or action (for example to complete authentication).
/// When <c>null</c>, the .NET CLI default is used.
/// </summary>
/// <remarks>
/// Supported by .NET SDK version 2.1.400 and above.
/// </remarks>
public bool Interactive { get; set; }
public bool? Interactive { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to enable project lock file to be generated and used with restore.
Expand Down
5 changes: 1 addition & 4 deletions src/Cake.Common/Tools/DotNet/Restore/DotNetRestorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ private ProcessArgumentBuilder GetArguments(string root, DotNetRestoreSettings s
}

// Interactive
if (settings.Interactive)
{
builder.Append("--interactive");
}
builder.AppendSwitch("--interactive", settings.Interactive);

// Use lock file
if (settings.UseLockFile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,9 @@ public sealed class DotNetToolInstallSettings : DotNetToolSettings

/// <summary>
/// Gets or sets a value indicating whether to create a tool manifest if one is not found.
/// When <c>null</c>, the .NET CLI default is used.
/// </summary>
public bool CreateManifestIfNeeded { get; set; }
public bool? CreateManifestIfNeeded { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to allow a .NET tool to roll forward to newer versions of the .NET runtime.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public sealed class DotNetWorkloadInstallSettings : DotNetSettings
/// <summary>
/// Gets or sets a value indicating whether to allow the command to stop and wait for user input or action.
/// For example, to complete authentication.
/// When <c>null</c>, the .NET CLI default is used.
/// </summary>
public bool Interactive { get; set; }
public bool? Interactive { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to do not cache packages and http requests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ private ProcessArgumentBuilder GetArguments(IEnumerable<string> workloadIds, Dot
}

// Interactive
if (settings.Interactive)
{
builder.Append("--interactive");
}
builder.AppendSwitch("--interactive", settings.Interactive);

// No Cache
if (settings.NoCache)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public sealed class DotNetWorkloadRestoreSettings : DotNetSettings
/// <summary>
/// Gets or sets a value indicating whether to allow the command to stop and wait for user input or action.
/// For example, to complete authentication.
/// When <c>null</c>, the .NET CLI default is used.
/// </summary>
public bool Interactive { get; set; }
public bool? Interactive { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to do not cache packages and http requests.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,7 @@ private ProcessArgumentBuilder GetArguments(string project, DotNetWorkloadRestor
}

// Interactive
if (settings.Interactive)
{
builder.Append("--interactive");
}
builder.AppendSwitch("--interactive", settings.Interactive);

// No Cache
if (settings.NoCache)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,37 @@ public void ShouldInsertFormattedTextArgument()
}
}

public class TheAppendSwitchBooleanMethods
{
[Theory]
[InlineData(true, "restore --interactive true")]
[InlineData(false, "restore --interactive false")]
[InlineData(null, "restore")]
public void ShouldAppendSwitchWithExplicitValue(bool? value, string expected)
{
var result = new ProcessArgumentBuilder()
.Append("restore")
.AppendSwitch("--interactive", value)
.RenderSafe();

Assert.Equal(expected, result);
}

[Theory]
[InlineData(true, "restore --interactive=true")]
[InlineData(false, "restore --interactive=false")]
[InlineData(null, "restore")]
public void ShouldAppendSwitchWithExplicitValueAndSeparator(bool? value, string expected)
{
var result = new ProcessArgumentBuilder()
.Append("restore")
.AppendSwitch("--interactive", "=", value)
.RenderSafe();

Assert.Equal(expected, result);
}
}

public class TheInsertSwitchMethods
{
[Fact]
Expand Down
39 changes: 39 additions & 0 deletions src/Cake.Core/Extensions/ProcessArgumentListExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,45 @@ public static ProcessArgumentBuilder AppendSwitch(this ProcessArgumentBuilder bu
return builder;
}

/// <summary>
/// Appends the specified switch with an explicit <c>true</c> or <c>false</c> value to the argument builder.
/// Nothing is appended when <paramref name="value"/> is <c>null</c>.
/// </summary>
/// <param name="builder">The builder.</param>
/// <param name="switch">The switch preceding the value.</param>
/// <param name="value">The value to be appended.</param>
/// <returns>The same <see cref="ProcessArgumentBuilder"/> instance so that multiple calls can be chained.</returns>
/// <example>
/// <code>
/// var args = new ProcessArgumentBuilder()
/// .Append("restore")
/// .AppendSwitch("--interactive", false);
/// </code>
/// </example>
public static ProcessArgumentBuilder AppendSwitch(this ProcessArgumentBuilder builder, string @switch, bool? value)
{
return AppendSwitch(builder, @switch, " ", value);
}

/// <summary>
/// Appends the specified switch with an explicit <c>true</c> or <c>false</c> value to the argument builder.
/// Nothing is appended when <paramref name="value"/> is <c>null</c>.
/// </summary>
/// <param name="builder">The builder.</param>
/// <param name="switch">The switch preceding the value.</param>
/// <param name="separator">The separator between the switch and value.</param>
/// <param name="value">The value to be appended.</param>
/// <returns>The same <see cref="ProcessArgumentBuilder"/> instance so that multiple calls can be chained.</returns>
public static ProcessArgumentBuilder AppendSwitch(this ProcessArgumentBuilder builder, string @switch, string separator, bool? value)
{
if (value.HasValue)
{
AppendSwitch(builder, @switch, separator, value.Value ? "true" : "false");
}

return builder;
}

/// <summary>
/// Prepend the specified switch to the argument builder.
/// </summary>
Expand Down
Loading