| File: Commands\SecretDeleteCommand.cs | Web Access |
| Project: src\src\Aspire.Cli\Aspire.Cli.csproj (aspire) |
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.CommandLine; using System.Globalization; using Aspire.Cli.Resources; using Aspire.Cli.Secrets; using Spectre.Console; namespace Aspire.Cli.Commands; /// <summary> /// Deletes a secret from an AppHost project. /// </summary> internal sealed class SecretDeleteCommand : BaseCommand { private static readonly Argument<string> s_keyArgument = new("key") { Description = SecretCommandStrings.KeyDeleteArgumentDescription }; private readonly SecretStoreResolver _secretStoreResolver; public SecretDeleteCommand( SecretStoreResolver secretStoreResolver, CommonCommandServices services) : base("delete", SecretCommandStrings.DeleteDescription, services) { _secretStoreResolver = secretStoreResolver; Arguments.Add(s_keyArgument); Options.Add(SecretCommand.s_appHostOption); } protected override async Task<CommandResult> ExecuteAsync(ParseResult parseResult, CancellationToken cancellationToken) { // Argument arity guarantees non-null var key = parseResult.GetValue(s_keyArgument)!; var projectFile = parseResult.GetValue(SecretCommand.s_appHostOption); var result = await _secretStoreResolver.ResolveAsync(projectFile, autoInit: false, cancellationToken); if (result is null) { return CommandResult.Failure(CliExitCodes.FailedToFindProject, SecretCommandStrings.CouldNotFindAppHost); } if (!result.Store.Remove(key)) { return CommandResult.Failure(CliExitCodes.ConfigNotFound, string.Format(CultureInfo.CurrentCulture, SecretCommandStrings.SecretNotFound, key.EscapeMarkup())); } result.Store.Save(); InteractionService.DisplaySuccess(string.Format(CultureInfo.CurrentCulture, SecretCommandStrings.SecretDeleteSuccess, key)); return CommandResult.Success(); } }