in Configurator/Core/CLI/CommandLine.cs [97:238]
public static CLIExitCode ProcessCommandLineOptions(ServerInstallation serverInstallation)
{
var showHelp = false;
PrintStartingText(serverInstallation);
// Identify if there is a help option.
if (CommandLineParser.GetMatchingProvidedOption("help") != null)
{
showHelp = true;
}
// Validate if an action option was provided to know for which action to show the help
// section or which action to execute.
var action = CommandLineParser.GetMatchingProvidedOption("action");
if (showHelp)
{
if (action == null)
{
PrintGeneralHelp();
}
else
{
PrintActionHelp(action.Value);
}
return new CLIExitCode(ExitCode.Success);
}
// Remove action option since it will no longer be needed.
if (action != null)
{
CommandLineParser.ProvidedOptions.Remove(action);
}
// Check for invalid configuration type when server is not yet configured.
if (serverInstallation.Controller.ConfigurationType == ConfigurationType.Reconfigure
&& !serverInstallation.Controller.Settings.GeneralSettingsFileExists)
{
return new CLIExitCode(ExitCode.ServerNotConfigured);
}
// Validate that all provided options are applicable to the specified action.
var optionsForConfigurationType = GetOptionsForAction(serverInstallation.Controller.ConfigurationType);
foreach (var option in CommandLineParser.ProvidedOptions)
{
if (!optionsForConfigurationType.Any(configTypeOption => configTypeOption.Name.Equals(option.Name, StringComparison.InvariantCultureIgnoreCase)))
{
return new CLIExitCode(ExitCode.InvalidOptionForAction, serverInstallation.Controller.ConfigurationType.ToString(), option.Name);
}
}
// Process special options
var result = ProcessSpecialCommandLineOptions(serverInstallation);
if (result.ExitCode != ExitCode.Success)
{
return result;
}
// Next we look for missing required options.
foreach (var option in optionsForConfigurationType)
{
if (option.Required
&& !CommandLineParser.ProvidedOptions.Any(providedOption => providedOption.Name.Equals(option.Name, StringComparison.InvariantCultureIgnoreCase)))
{
if (option.Name.Equals("password", StringComparison.InvariantCultureIgnoreCase)
|| option.Name.Equals("old-instance-password", StringComparison.InvariantCultureIgnoreCase))
{
// Skip already processed special options.
continue;
}
return new CLIExitCode(ExitCode.MissingRequiredOption, option.Name);
}
}
// Process special cases
if (serverInstallation.Controller.ConfigurationType == ConfigurationType.Reconfigure)
{
if (CommandLineParser.ProvidedOptions.Count == 0)
{
return new CLIExitCode(ExitCode.MissingOptionToReconfigure);
}
}
// Set the values in the controller.
foreach (var option in CommandLineParser.ProvidedOptions)
{
// Try to assign the provided value to the option.
if (!TryToSetValue(serverInstallation.Controller, option.Name, option.Value))
{
return new CLIExitCode(ExitCode.InvalidOptionValue, option.Value, option.Name);
}
}
CommandLineParser.ProvidedOptions.Clear();
// Final validations for specific configuration types.
if (serverInstallation.Controller.ConfigurationType == ConfigurationType.Reconfigure)
{
// Perform a connection check.
var connectionResult = MySqlServerInstance.CanConnect(serverInstallation.Controller, serverInstallation.Controller.ConfigurationType == ConfigurationType.Reconfigure
? serverInstallation.Controller.Settings.ExistingRootPassword
: serverInstallation.Controller.Settings.RootPassword, true);
if (connectionResult != ConnectionResultType.ConnectionSuccess)
{
return new CLIExitCode(ExitCode.FailedConnectionTestDuringReconfiguration, connectionResult.GetDescription());
}
Console.WriteLine(Resources.CLISuccessfulConnection);
}
else if (serverInstallation.Controller.ConfigurationType == ConfigurationType.Upgrade)
{
var upgradeViableResult = IsUpgradeViable(serverInstallation);
if (upgradeViableResult.ExitCode != ExitCode.Success)
{
return upgradeViableResult;
}
}
// Execute operation.
if (serverInstallation.Controller.ConfigurationType == ConfigurationType.Remove)
{
serverInstallation.Controller.UpdateRemoveSteps();
if (!serverInstallation.Controller.IsRemovalExecutionNeeded)
{
Console.WriteLine(Resources.CLINoConfigurationsFound);
return new CLIExitCode(ExitCode.Success);
};
}
else
{
serverInstallation.Controller.UpdateConfigurationSteps();
}
var configurationState = ExecuteOperation(serverInstallation);
// Return result of operation execution.
return configurationState == ConfigState.ConfigurationComplete
|| configurationState == ConfigState.ConfigurationCompleteWithWarnings
? new CLIExitCode(ExitCode.Success)
: new CLIExitCode(ExitCode.FailedConfiguration);
}