public IReadOnlyList <UpgradeCommand> GetCommands(UpgradeStep step, IUpgradeContext context) { if (step is null) { throw new ArgumentNullException(nameof(step)); } if (context is null) { throw new ArgumentNullException(nameof(context)); } var commands = new List <UpgradeCommand> { new ApplyNextCommand(step), new SkipNextCommand(step), new SeeMoreDetailsCommand(step, ShowStepStatus) }; if (context.Projects.Count() > 1 && context.CurrentProject is not null) { commands.Add(new SelectProjectCommand()); } commands.Add(new ConfigureConsoleLoggingCommand(_userInput, _logSettings)); commands.Add(_exit); return(commands); }
private async Task ShowStepStatus(UpgradeStep step) { Console.ForegroundColor = ConsoleColor.Cyan; await _io.Output.WriteLineAsync(new string('-', step.Title.Length)); await _io.Output.WriteLineAsync($"{step.Title}"); await _io.Output.WriteLineAsync(new string('-', step.Title.Length)); Console.ResetColor(); await _io.Output.WriteLineAsync(ConsoleHelpers.WrapString(step.Description, Console.WindowWidth)); await WriteWithColorAsync(" Status ", ConsoleColor.DarkYellow); await _io.Output.WriteAsync(": "); await _io.Output.WriteLineAsync($"{step.Status}"); await WriteWithColorAsync(" Risk to break build ", ConsoleColor.DarkYellow); await _io.Output.WriteAsync(": "); await _io.Output.WriteLineAsync($"{step.Risk}"); await WriteWithColorAsync(" Details ", ConsoleColor.DarkYellow); await _io.Output.WriteAsync(": "); await _io.Output.WriteLineAsync(ConsoleHelpers.WrapString($"{step.StatusDetails}", Console.WindowWidth, " Details : ".Length)); }
private async Task RunStepAsync(IUpgradeContext context, UpgradeStep step, CancellationToken token) { token.ThrowIfCancellationRequested(); await _io.Output.WriteLineAsync(); var commands = _commandProvider.GetCommands(step, context); var command = await _input.ChooseAsync("Choose a command:", commands, token); // TODO : It might be nice to allow commands to show more details by having a 'status' property // that can be shown here. Also, commands currently only return bools but, in the future, // if they return more complex objects, custom handlers could be used to respond to the different // commands' return values. if (!await ExecuteAndTimeCommand(context, step, command, token)) { Console.ForegroundColor = ConsoleColor.Yellow; await _io.Output.WriteAsync($"Command ({command.CommandText}) did not succeed"); Console.ResetColor(); } else if (!await _input.WaitToProceedAsync(token)) { _logger.LogWarning("Upgrade process was canceled. Quitting...."); } token.ThrowIfCancellationRequested(); }
private void WriteStepStatus(UpgradeStep step, bool isNextStep) { switch (step.Status) { case UpgradeStepStatus.Complete: Console.ForegroundColor = ConsoleColor.Green; _io.Output.Write("[Complete] "); break; case UpgradeStepStatus.Failed: Console.ForegroundColor = ConsoleColor.Red; _io.Output.Write("[Failed] "); break; case UpgradeStepStatus.Skipped: Console.ForegroundColor = ConsoleColor.DarkYellow; _io.Output.Write("[Skipped] "); break; case UpgradeStepStatus.Incomplete: if (isNextStep) { Console.ForegroundColor = ConsoleColor.Yellow; _io.Output.Write("[Next step] "); } break; } Console.ResetColor(); }
private void WriteStepStatus(UpgradeStep step, bool isNextStep) { (ConsoleColor? color, var output) = step.Status switch { UpgradeStepStatus.Complete => (ConsoleColor.Green, "[Complete] "), UpgradeStepStatus.Failed => (ConsoleColor.Red, "[Failed] "), UpgradeStepStatus.Skipped => (ConsoleColor.DarkYellow, "[Skipped] "), UpgradeStepStatus.Incomplete when isNextStep => (ConsoleColor.Yellow, "[Next step] "), _ => default }; if (color.HasValue && output is { Length : > 0 })
public IReadOnlyList <UpgradeCommand> GetCommands(UpgradeStep step) { if (step is null) { throw new ArgumentNullException(nameof(step)); } return(new List <UpgradeCommand>() { new ApplyNextCommand(step), new SkipNextCommand(step), new SeeMoreDetailsCommand(step, ShowStepStatus), new ConfigureConsoleLoggingCommand(_userInput, _logSettings), _exit, }); }
private Task ShowStepStatus(UpgradeStep step) { Console.ForegroundColor = ConsoleColor.Cyan; _io.Output.WriteLine(new string('-', step.Title.Length)); _io.Output.WriteLine($"{step.Title}"); _io.Output.WriteLine(new string('-', step.Title.Length)); Console.ResetColor(); _io.Output.WriteLine(ConsoleHelpers.WrapString(step.Description, Console.WindowWidth)); WriteWithColor(" Status ", ConsoleColor.DarkYellow); _io.Output.Write(": "); _io.Output.WriteLine($"{step.Status}"); WriteWithColor(" Risk to break build ", ConsoleColor.DarkYellow); _io.Output.Write(": "); _io.Output.WriteLine($"{step.Risk}"); WriteWithColor(" Details ", ConsoleColor.DarkYellow); _io.Output.Write(": "); _io.Output.WriteLine(ConsoleHelpers.WrapString($"{step.StatusDetails}", Console.WindowWidth, " Details : ".Length)); return(Task.CompletedTask); }
protected AutoApplySubStep(UpgradeStep parentStep, ILogger logger) : base(logger) { _parentStep = parentStep; }
public ApplyNextCommand(UpgradeStep step) { _step = step ?? throw new ArgumentNullException(nameof(step)); }
private async ValueTask <bool> ExecuteAndTimeCommand(IUpgradeContext context, UpgradeStep step, UpgradeCommand command, CancellationToken token) { using (_telemetry.TimeStep(command.Id, step)) { return(await command.ExecuteAsync(context, token)); } }
public SeeMoreDetailsCommand(UpgradeStep step, Func <UpgradeStep, Task> showDetails) { _step = step ?? throw new ArgumentNullException(nameof(step)); _showDetails = showDetails ?? throw new ArgumentNullException(nameof(showDetails)); }
public ConfigUpdaterSubStep(UpgradeStep parentStep, IUpdater <ConfigFile> configUpdater, ILogger logger) : base(logger) { _parentStep = (ParentStep = parentStep) as ConfigUpdaterStep ?? throw new ArgumentNullException(nameof(parentStep)); _configUpdater = configUpdater ?? throw new ArgumentNullException(nameof(configUpdater)); }