Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions src/Aspire.Cli/Commands/BaseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;
using System.Globalization;
using Aspire.Cli.Configuration;
using Aspire.Cli.Interaction;
using Aspire.Cli.Projects;
using Aspire.Cli.Resources;
using Aspire.Cli.Telemetry;
using Aspire.Cli.Utils;

Expand Down Expand Up @@ -103,4 +105,17 @@ internal static int HandleProjectLocatorException(ProjectLocatorException ex, II
interactionService.DisplayError(errorMessage);
return exitCode;
}

internal static void AddNonInteractiveRequiresYesValidator(Command command, Option<bool> yesOption)
{
command.Validators.Add(result =>
{
var nonInteractive = result.GetValue(RootCommand.NonInteractiveOption);
var yes = result.GetValue(yesOption);
if (nonInteractive && !yes)
{
result.AddError(string.Format(CultureInfo.CurrentCulture, SharedCommandStrings.NonInteractiveRequiresYesFormat, command.Name));
}
});
}
}
10 changes: 1 addition & 9 deletions src/Aspire.Cli/Commands/DestroyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,7 @@ public DestroyCommand(IDotNetCliRunner runner, IInteractionService interactionSe
};
Options.Add(_yesOption);

Validators.Add(result =>
{
var nonInteractive = result.GetValue(RootCommand.NonInteractiveOption);
var yes = result.GetValue(_yesOption);
if (nonInteractive && !yes)
{
result.AddError(DestroyCommandStrings.NonInteractiveRequiresYes);
}
});
AddNonInteractiveRequiresYesValidator(this, _yesOption);
}

protected override string OperationCompletedPrefix => DestroyCommandStrings.OperationCompletedPrefix;
Expand Down
4 changes: 3 additions & 1 deletion src/Aspire.Cli/Commands/UpdateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ public UpdateCommand(
Options.Add(s_yesOption);
Options.Add(s_nugetConfigDirOption);

AddNonInteractiveRequiresYesValidator(this, s_yesOption);

// Customize description based on whether staging channel is enabled
var isStagingEnabled = KnownFeatures.IsStagingChannelEnabled(_features, _configuration);

Expand Down Expand Up @@ -222,7 +224,7 @@ protected override async Task<int> ExecuteAsync(ParseResult parseResult, Cancell
}

// Update packages using the appropriate project handler
var confirmBinding = PromptBinding.CreateWithInteractiveDefault(parseResult, s_yesOption, true);
var confirmBinding = PromptBinding.Create(parseResult, s_yesOption, defaultValue: true);
Comment thread
JamesNK marked this conversation as resolved.
var nugetConfigDirBinding = PromptBinding.Create(parseResult, s_nugetConfigDirOption);
var updateContext = new UpdatePackagesContext
{
Expand Down
7 changes: 0 additions & 7 deletions src/Aspire.Cli/Interaction/PromptBinding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,6 @@ public static PromptBinding<T> Create<T>(ParseResult parseResult, Option<T> opti
public static PromptBinding<T> Create<T>(ParseResult parseResult, Option<T> option, T defaultValue) =>
new(parseResult, FormatOptionName(option), BuildOptionResolver(option), defaultValue, hasExplicitDefault: true);

/// <summary>
/// Creates a <see cref="PromptBinding{T}"/> that uses <paramref name="interactiveDefault"/> as the
/// default for interactive prompts but still requires the CLI option in non-interactive mode.
/// </summary>
public static PromptBinding<T> CreateWithInteractiveDefault<T>(ParseResult parseResult, Option<T> option, T interactiveDefault) =>
new(parseResult, FormatOptionName(option), BuildOptionResolver(option), interactiveDefault, hasExplicitDefault: false);

/// <summary>
/// Creates a <see cref="PromptBinding{T}"/> with only a default value and no CLI symbol binding.
/// Use when there is no corresponding CLI option or argument for the prompt.
Expand Down
9 changes: 0 additions & 9 deletions src/Aspire.Cli/Resources/DestroyCommandStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions src/Aspire.Cli/Resources/DestroyCommandStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,6 @@
<data name="Description" xml:space="preserve">
<value>Destroy a previously deployed AppHost environment (Preview)</value>
</data>
<data name="NonInteractiveRequiresYes" xml:space="preserve">
<value>The destroy command requires --yes when the --non-interactive option is specified.</value>
</data>
<data name="OutputPathArgumentDescription" xml:space="preserve">
<value>The output path containing the deployment artifacts to destroy</value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions src/Aspire.Cli/Resources/SharedCommandStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/Aspire.Cli/Resources/SharedCommandStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,8 @@
<data name="PipelineStepsSummaryTitle" xml:space="preserve">
<value>Steps Summary:</value>
</data>
<data name="NonInteractiveRequiresYesFormat" xml:space="preserve">
<value>The {0} command requires --yes when the --non-interactive option is specified.</value>
<comment>{0} is the command name.</comment>
</data>
</root>
5 changes: 0 additions & 5 deletions src/Aspire.Cli/Resources/xlf/DestroyCommandStrings.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/Aspire.Cli/Resources/xlf/DestroyCommandStrings.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/Aspire.Cli/Resources/xlf/DestroyCommandStrings.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/Aspire.Cli/Resources/xlf/DestroyCommandStrings.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/Aspire.Cli/Resources/xlf/DestroyCommandStrings.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/Aspire.Cli/Resources/xlf/DestroyCommandStrings.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/Aspire.Cli/Resources/xlf/DestroyCommandStrings.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/Aspire.Cli/Resources/xlf/DestroyCommandStrings.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/Aspire.Cli/Resources/xlf/DestroyCommandStrings.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions src/Aspire.Cli/Resources/xlf/DestroyCommandStrings.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Aspire.Cli/Resources/xlf/SharedCommandStrings.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Aspire.Cli/Resources/xlf/SharedCommandStrings.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Aspire.Cli/Resources/xlf/SharedCommandStrings.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Aspire.Cli/Resources/xlf/SharedCommandStrings.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Aspire.Cli/Resources/xlf/SharedCommandStrings.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Aspire.Cli/Resources/xlf/SharedCommandStrings.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Aspire.Cli/Resources/xlf/SharedCommandStrings.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Aspire.Cli/Resources/xlf/SharedCommandStrings.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading