private Command BuildDeleteCommand()

in src/AWS.Deploy.CLI/Commands/CommandFactory.cs [257:340]


        private Command BuildDeleteCommand()
        {
            var deleteCommand = new Command("delete-deployment", "Delete an existing deployment.");
            lock (s_child_command_lock)
            {
                deleteCommand.Add(_optionProfile);
                deleteCommand.Add(_optionRegion);
                deleteCommand.Add(_optionProjectPath);
                deleteCommand.Add(_optionDiagnosticLogging);
                deleteCommand.AddArgument(new Argument("deployment-name"));
            }

            deleteCommand.Handler = CommandHandler.Create(async (DeleteCommandHandlerInput input) =>
            {
                try
                {
                    _toolInteractiveService.Diagnostics = input.Diagnostics;

                    var awsCredentials = await _awsUtilities.ResolveAWSCredentials(input.Profile);
                    var awsRegion = _awsUtilities.ResolveAWSRegion(input.Region);

                    _awsClientFactory.ConfigureAWSOptions(awsOption =>
                    {
                        awsOption.Credentials = awsCredentials;
                        awsOption.Region = RegionEndpoint.GetBySystemName(awsRegion);
                    });

                    if (string.IsNullOrEmpty(input.DeploymentName))
                    {
                        _toolInteractiveService.WriteErrorLine(string.Empty);
                        _toolInteractiveService.WriteErrorLine("Deployment name cannot be empty. Please provide a valid deployment name and try again.");
                        return CommandReturnCodes.USER_ERROR;
                    }

                    OrchestratorSession? session = null;

                    try
                    {
                        var projectDefinition = await _projectParserUtility.Parse(input.ProjectPath ?? string.Empty);

                        var callerIdentity = await _awsResourceQueryer.GetCallerIdentity();

                        session = new OrchestratorSession(
                            projectDefinition,
                            awsCredentials,
                            awsRegion,
                            callerIdentity.Account);
                    }
                    catch (FailedToFindDeployableTargetException) { }

                    await new DeleteDeploymentCommand(
                        _awsClientFactory,
                        _toolInteractiveService,
                        _consoleUtilities,
                        _localUserSettingsEngine,
                        session).ExecuteAsync(input.DeploymentName);

                    return CommandReturnCodes.SUCCESS;
                }
                catch (Exception e) when (e.IsAWSDeploymentExpectedException())
                {
                    if (input.Diagnostics)
                        _toolInteractiveService.WriteErrorLine(e.PrettyPrint());
                    else
                    {
                        _toolInteractiveService.WriteErrorLine(string.Empty);
                        _toolInteractiveService.WriteErrorLine(e.Message);
                    }

                    // bail out with an non-zero return code.
                    return CommandReturnCodes.USER_ERROR;
                }
                catch (Exception e)
                {
                    // This is a bug
                    _toolInteractiveService.WriteErrorLine(
                        "Unhandled exception.  This is a bug.  Please copy the stack trace below and file a bug at https://github.com/aws/aws-dotnet-deploy. " +
                        e.PrettyPrint());

                    return CommandReturnCodes.UNHANDLED_EXCEPTION;
                }
            });
            return deleteCommand;
        }