in src/AWS.Deploy.CLI/Commands/CommandFactory.cs [530:585]
private Command BuildServerModeCommand()
{
var serverModeCommand = new Command(
"server-mode",
"Launches the tool in a server mode for IDEs like Visual Studio to integrate with.");
lock (s_child_command_lock)
{
serverModeCommand.Add(new Option<int>(new[] { "--port" }, description: "Port the server mode will listen to."));
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."));
serverModeCommand.Add(new Option<bool>(new[] { "--unsecure-mode" }, description: "If set the cli uses an unsecure mode without encryption."));
serverModeCommand.Add(_optionDiagnosticLogging);
}
serverModeCommand.Handler = CommandHandler.Create(async (ServerModeCommandHandlerInput input) =>
{
try
{
_toolInteractiveService.Diagnostics = input.Diagnostics;
var serverMode = new ServerModeCommand(_toolInteractiveService, input.Port, input.ParentPid, input.UnsecureMode);
await serverMode.ExecuteAsync();
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);
}
if (e is TcpPortInUseException)
{
return CommandReturnCodes.TCP_PORT_ERROR;
}
// 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 serverModeCommand;
}