Skip to content

Commit ff3e778

Browse files
committed
commi 4
1 parent da3ed0a commit ff3e778

File tree

17 files changed

+646
-541
lines changed

17 files changed

+646
-541
lines changed

src/AWS.Deploy.CLI/Commands/CommandFactory.cs

+58-58
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public Command BuildRootCommand()
158158
// rootCommand.Add(BuildListCommand());
159159
// rootCommand.Add(BuildDeleteCommand());
160160
// rootCommand.Add(BuildDeploymentProjectCommand());
161-
rootCommand.Add(BuildServerModeCommand());
161+
// rootCommand.Add(BuildServerModeCommand());
162162
}
163163

164164
rootCommand.Handler = CommandHandler.Create((bool version) =>
@@ -524,62 +524,62 @@ public Command BuildRootCommand()
524524
//
525525
// return deploymentProjectCommand;
526526
// }
527-
528-
private Command BuildServerModeCommand()
529-
{
530-
var serverModeCommand = new Command(
531-
"server-mode",
532-
"Launches the tool in a server mode for IDEs like Visual Studio to integrate with.");
533-
534-
lock (s_child_command_lock)
535-
{
536-
serverModeCommand.Add(new Option<int>(new[] { "--port" }, description: "Port the server mode will listen to."));
537-
serverModeCommand.Add(new Option<int>(new[] { "--parent-pid" }, description: "The ID of the process that is launching server mode. Server mode will exit when the parent pid terminates."));
538-
serverModeCommand.Add(new Option<bool>(new[] { "--unsecure-mode" }, description: "If set the cli uses an unsecure mode without encryption."));
539-
serverModeCommand.Add(_optionDiagnosticLogging);
540-
}
541-
542-
serverModeCommand.Handler = CommandHandler.Create(async (ServerModeCommandHandlerInput input) =>
543-
{
544-
try
545-
{
546-
_toolInteractiveService.Diagnostics = input.Diagnostics;
547-
var serverMode = new ServerModeCommand(_toolInteractiveService, input.Port, input.ParentPid, input.UnsecureMode);
548-
549-
await serverMode.ExecuteAsync();
550-
551-
return CommandReturnCodes.SUCCESS;
552-
}
553-
catch (Exception e) when (e.IsAWSDeploymentExpectedException())
554-
{
555-
if (input.Diagnostics)
556-
_toolInteractiveService.WriteErrorLine(e.PrettyPrint());
557-
else
558-
{
559-
_toolInteractiveService.WriteErrorLine(string.Empty);
560-
_toolInteractiveService.WriteErrorLine(e.Message);
561-
}
562-
563-
if (e is TcpPortInUseException)
564-
{
565-
return CommandReturnCodes.TCP_PORT_ERROR;
566-
}
567-
568-
// bail out with an non-zero return code.
569-
return CommandReturnCodes.USER_ERROR;
570-
}
571-
catch (Exception e)
572-
{
573-
// This is a bug
574-
_toolInteractiveService.WriteErrorLine(
575-
"Unhandled exception. This is a bug. Please copy the stack trace below and file a bug at https://github.com/aws/aws-dotnet-deploy. " +
576-
e.PrettyPrint());
577-
578-
return CommandReturnCodes.UNHANDLED_EXCEPTION;
579-
}
580-
});
581-
582-
return serverModeCommand;
583-
}
527+
//
528+
// private Command BuildServerModeCommand()
529+
// {
530+
// var serverModeCommand = new Command(
531+
// "server-mode",
532+
// "Launches the tool in a server mode for IDEs like Visual Studio to integrate with.");
533+
//
534+
// lock (s_child_command_lock)
535+
// {
536+
// serverModeCommand.Add(new Option<int>(new[] { "--port" }, description: "Port the server mode will listen to."));
537+
// serverModeCommand.Add(new Option<int>(new[] { "--parent-pid" }, description: "The ID of the process that is launching server mode. Server mode will exit when the parent pid terminates."));
538+
// serverModeCommand.Add(new Option<bool>(new[] { "--unsecure-mode" }, description: "If set the cli uses an unsecure mode without encryption."));
539+
// serverModeCommand.Add(_optionDiagnosticLogging);
540+
// }
541+
//
542+
// serverModeCommand.Handler = CommandHandler.Create(async (ServerModeCommandHandlerInput input) =>
543+
// {
544+
// try
545+
// {
546+
// _toolInteractiveService.Diagnostics = input.Diagnostics;
547+
// var serverMode = new ServerModeCommand(_toolInteractiveService, input.Port, input.ParentPid, input.UnsecureMode);
548+
//
549+
// await serverMode.ExecuteAsync();
550+
//
551+
// return CommandReturnCodes.SUCCESS;
552+
// }
553+
// catch (Exception e) when (e.IsAWSDeploymentExpectedException())
554+
// {
555+
// if (input.Diagnostics)
556+
// _toolInteractiveService.WriteErrorLine(e.PrettyPrint());
557+
// else
558+
// {
559+
// _toolInteractiveService.WriteErrorLine(string.Empty);
560+
// _toolInteractiveService.WriteErrorLine(e.Message);
561+
// }
562+
//
563+
// if (e is TcpPortInUseException)
564+
// {
565+
// return CommandReturnCodes.TCP_PORT_ERROR;
566+
// }
567+
//
568+
// // bail out with an non-zero return code.
569+
// return CommandReturnCodes.USER_ERROR;
570+
// }
571+
// catch (Exception e)
572+
// {
573+
// // This is a bug
574+
// _toolInteractiveService.WriteErrorLine(
575+
// "Unhandled exception. This is a bug. Please copy the stack trace below and file a bug at https://github.com/aws/aws-dotnet-deploy. " +
576+
// e.PrettyPrint());
577+
//
578+
// return CommandReturnCodes.UNHANDLED_EXCEPTION;
579+
// }
580+
// });
581+
//
582+
// return serverModeCommand;
583+
// }
584584
}
585585
}

src/AWS.Deploy.CLI/Commands/DeleteDeploymentCommand.cs

+58-83
Original file line numberDiff line numberDiff line change
@@ -61,111 +61,86 @@ public DeleteDeploymentCommand(
6161
/// <exception cref="FailedToDeleteException">Thrown when deletion fails</exception>
6262
public override async Task<int> ExecuteAsync(CommandContext context, DeleteDeploymentCommandSettings settings, CancellationTokenSource cancellationTokenSource)
6363
{
64-
try
65-
{
66-
_interactiveService.Diagnostics = settings.Diagnostics;
67-
_interactiveService.DisableInteractive = settings.Silent;
64+
_interactiveService.Diagnostics = settings.Diagnostics;
65+
_interactiveService.DisableInteractive = settings.Silent;
6866

69-
var (awsCredentials, regionFromProfile) = await _awsUtilities.ResolveAWSCredentials(settings.Profile);
70-
var awsRegion = _awsUtilities.ResolveAWSRegion(settings.Region ?? regionFromProfile);
67+
var (awsCredentials, regionFromProfile) = await _awsUtilities.ResolveAWSCredentials(settings.Profile);
68+
var awsRegion = _awsUtilities.ResolveAWSRegion(settings.Region ?? regionFromProfile);
7169

72-
_awsClientFactory.ConfigureAWSOptions(awsOption =>
73-
{
74-
awsOption.Credentials = awsCredentials;
75-
awsOption.Region = RegionEndpoint.GetBySystemName(awsRegion);
76-
});
70+
_awsClientFactory.ConfigureAWSOptions(awsOption =>
71+
{
72+
awsOption.Credentials = awsCredentials;
73+
awsOption.Region = RegionEndpoint.GetBySystemName(awsRegion);
74+
});
7775

78-
if (string.IsNullOrEmpty(settings.DeploymentName))
79-
{
80-
_interactiveService.WriteErrorLine(string.Empty);
81-
_interactiveService.WriteErrorLine("Deployment name cannot be empty. Please provide a valid deployment name and try again.");
82-
return CommandReturnCodes.USER_ERROR;
83-
}
76+
if (string.IsNullOrEmpty(settings.DeploymentName))
77+
{
78+
_interactiveService.WriteErrorLine(string.Empty);
79+
_interactiveService.WriteErrorLine("Deployment name cannot be empty. Please provide a valid deployment name and try again.");
80+
return CommandReturnCodes.USER_ERROR;
81+
}
8482

85-
OrchestratorSession? session = null;
83+
OrchestratorSession? session = null;
8684

87-
try
88-
{
89-
var projectDefinition = await _projectParserUtility.Parse(settings.ProjectPath ?? string.Empty);
85+
try
86+
{
87+
var projectDefinition = await _projectParserUtility.Parse(settings.ProjectPath);
9088

91-
var callerIdentity = await _awsResourceQueryer.GetCallerIdentity(awsRegion);
89+
var callerIdentity = await _awsResourceQueryer.GetCallerIdentity(awsRegion);
9290

93-
session = new OrchestratorSession(
94-
projectDefinition,
95-
awsCredentials,
96-
awsRegion,
97-
callerIdentity.Account);
98-
}
99-
catch (FailedToFindDeployableTargetException) { }
91+
session = new OrchestratorSession(
92+
projectDefinition,
93+
awsCredentials,
94+
awsRegion,
95+
callerIdentity.Account);
96+
}
97+
catch (FailedToFindDeployableTargetException) { }
10098

101-
var canDelete = await CanDeleteAsync(settings.DeploymentName);
102-
if (!canDelete)
103-
{
104-
return CommandReturnCodes.SUCCESS;
105-
}
99+
var canDelete = await CanDeleteAsync(settings.DeploymentName);
100+
if (!canDelete)
101+
{
102+
return CommandReturnCodes.SUCCESS;
103+
}
106104

107-
var confirmDelete = _interactiveService.DisableInteractive
108-
? YesNo.Yes
109-
: _consoleUtilities.AskYesNoQuestion($"Are you sure you want to delete {settings.DeploymentName}?", YesNo.No);
105+
var confirmDelete = _interactiveService.DisableInteractive
106+
? YesNo.Yes
107+
: _consoleUtilities.AskYesNoQuestion($"Are you sure you want to delete {settings.DeploymentName}?", YesNo.No);
110108

111-
if (confirmDelete == YesNo.No)
112-
{
113-
return CommandReturnCodes.SUCCESS;
114-
}
109+
if (confirmDelete == YesNo.No)
110+
{
111+
return CommandReturnCodes.SUCCESS;
112+
}
115113

116-
_interactiveService.WriteLine($"{settings.DeploymentName}: deleting...");
117-
var monitor = new StackEventMonitor(settings.DeploymentName, _awsClientFactory, _consoleUtilities, _interactiveService);
114+
_interactiveService.WriteLine($"{settings.DeploymentName}: deleting...");
115+
var monitor = new StackEventMonitor(settings.DeploymentName, _awsClientFactory, _consoleUtilities, _interactiveService);
118116

119-
try
117+
try
118+
{
119+
await _cloudFormationClient.DeleteStackAsync(new DeleteStackRequest
120120
{
121-
await _cloudFormationClient.DeleteStackAsync(new DeleteStackRequest
122-
{
123-
StackName = settings.DeploymentName
124-
});
125-
126-
// Fire and forget the monitor
127-
// Monitor updates the stdout with current status of the CloudFormation stack
128-
var _ = monitor.StartAsync();
121+
StackName = settings.DeploymentName
122+
});
129123

130-
await WaitForStackDelete(settings.DeploymentName);
124+
// Fire and forget the monitor
125+
// Monitor updates the stdout with current status of the CloudFormation stack
126+
var _ = monitor.StartAsync();
131127

132-
if (session != null)
133-
{
134-
await _localUserSettingsEngine.DeleteLastDeployedStack(settings.DeploymentName, session.ProjectDefinition.ProjectName, session.AWSAccountId, session.AWSRegion);
135-
}
128+
await WaitForStackDelete(settings.DeploymentName);
136129

137-
_interactiveService.WriteLine($"{settings.DeploymentName}: deleted");
138-
}
139-
finally
130+
if (session != null)
140131
{
141-
// Stop monitoring CloudFormation stack status once the deletion operation finishes
142-
monitor.Stop();
132+
await _localUserSettingsEngine.DeleteLastDeployedStack(settings.DeploymentName, session.ProjectDefinition.ProjectName, session.AWSAccountId, session.AWSRegion);
143133
}
144134

145-
return CommandReturnCodes.SUCCESS;
135+
_interactiveService.WriteLine($"{settings.DeploymentName}: deleted");
146136
}
147-
catch (Exception e) when (e.IsAWSDeploymentExpectedException())
137+
finally
148138
{
149-
if (settings.Diagnostics)
150-
_interactiveService.WriteErrorLine(e.PrettyPrint());
151-
else
152-
{
153-
_interactiveService.WriteErrorLine(string.Empty);
154-
_interactiveService.WriteErrorLine(e.Message);
155-
}
156-
157-
// bail out with an non-zero return code.
158-
return CommandReturnCodes.USER_ERROR;
139+
// Stop monitoring CloudFormation stack status once the deletion operation finishes
140+
monitor.Stop();
159141
}
160-
catch (Exception e)
161-
{
162-
// This is a bug
163-
_interactiveService.WriteErrorLine(
164-
"Unhandled exception. This is a bug. Please copy the stack trace below and file a bug at https://github.com/aws/aws-dotnet-deploy. " +
165-
e.PrettyPrint());
166142

167-
return CommandReturnCodes.UNHANDLED_EXCEPTION;
168-
}
143+
return CommandReturnCodes.SUCCESS;
169144
}
170145

171146
private async Task<bool> CanDeleteAsync(string stackName)
@@ -226,7 +201,7 @@ private async Task WaitForStackDelete(string stackName)
226201
private async Task<Stack?> GetStackAsync(string stackName)
227202
{
228203
var retryCount = 0;
229-
var shouldRetry = false;
204+
bool shouldRetry;
230205

231206
Stack? stack = null;
232207
do

0 commit comments

Comments
 (0)