Skip to content

Commit

Permalink
feat: Add support for --silent flag in the delete-deployment command
Browse files Browse the repository at this point in the history
  • Loading branch information
96malhar committed Feb 14, 2022
1 parent b245f33 commit 0682ce3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/AWS.Deploy.CLI/Commands/CommandFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class CommandFactory : ICommandFactory
private static readonly Option<string> _optionApplicationName = new("--application-name", "Name of the cloud application. If you choose to deploy via CloudFormation, this name will be used to identify the CloudFormation stack.");
private static readonly Option<bool> _optionDiagnosticLogging = new(new[] { "-d", "--diagnostics" }, "Enable diagnostic output.");
private static readonly Option<string> _optionApply = new("--apply", "Path to the deployment settings file to be applied.");
private static readonly Option<bool> _optionDisableInteractive = new(new[] { "-s", "--silent" }, "Disable interactivity to deploy without any prompts for user input.");
private static readonly Option<bool> _optionDisableInteractive = new(new[] { "-s", "--silent" }, "Disable interactivity to execute commands without any prompts for user input.");
private static readonly Option<string> _optionOutputDirectory = new(new[] { "-o", "--output" }, "Directory path in which the CDK deployment project will be saved.");
private static readonly Option<string> _optionProjectDisplayName = new(new[] { "--project-display-name" }, "The name of the deployment project that will be displayed in the list of available deployment options.");
private static readonly Option<string> _optionDeploymentProject = new(new[] { "--deployment-project" }, "The absolute or relative path of the CDK project that will be used for deployment");
Expand Down Expand Up @@ -268,6 +268,7 @@ private Command BuildDeleteCommand()
deleteCommand.Add(_optionRegion);
deleteCommand.Add(_optionProjectPath);
deleteCommand.Add(_optionDiagnosticLogging);
deleteCommand.Add(_optionDisableInteractive);
deleteCommand.AddArgument(new Argument("deployment-name"));
}

Expand All @@ -276,6 +277,7 @@ private Command BuildDeleteCommand()
try
{
_toolInteractiveService.Diagnostics = input.Diagnostics;
_toolInteractiveService.DisableInteractive = input.Silent;

var awsCredentials = await _awsUtilities.ResolveAWSCredentials(input.Profile);
var awsRegion = _awsUtilities.ResolveAWSRegion(input.Region);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ public class DeleteCommandHandlerInput
public string? ProjectPath { get; set; }
public string? DeploymentName { get; set; }
public bool Diagnostics { get; set; }
public bool Silent { get; set; }
}
}
5 changes: 4 additions & 1 deletion src/AWS.Deploy.CLI/Commands/DeleteDeploymentCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ public async Task ExecuteAsync(string stackName)
return;
}

var confirmDelete = _consoleUtilities.AskYesNoQuestion($"Are you sure you want to delete {stackName}?", YesNo.No);
var confirmDelete = _interactiveService.DisableInteractive
? YesNo.Yes
: _consoleUtilities.AskYesNoQuestion($"Are you sure you want to delete {stackName}?", YesNo.No);

if (confirmDelete == YesNo.No)
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,8 @@ public async Task DefaultConfigurations()
Assert.Contains(listStdOut, (deployment) => _stackName.Equals(deployment));

// Arrange input for delete
await _interactiveService.StdInWriter.WriteAsync("y"); // Confirm delete
await _interactiveService.StdInWriter.FlushAsync();
var deleteArgs = new[] { "delete-deployment", _stackName, "--diagnostics" };
// Use --silent flag to delete without user prompts
var deleteArgs = new[] { "delete-deployment", _stackName, "--diagnostics", "--silent" };

// Delete
Assert.Equal(CommandReturnCodes.SUCCESS, await _app.Run(deleteArgs));;
Expand Down

0 comments on commit 0682ce3

Please sign in to comment.