/// <summary> /// Initializes an instance of <see cref="CliApplication"/>. /// </summary> internal CliApplication(IServiceProvider serviceProvider, IConsole console, EnvironmentVariablesAccessor environmentVariablesAccessor, ApplicationMetadata metadata, Action <ApplicationMetadata, IConsole>?startupMessage) { _serviceProvider = serviceProvider; _environmentVariablesAccessor = environmentVariablesAccessor; _metadata = metadata; _startupMessage = startupMessage; _console = console; _logger = serviceProvider.GetRequiredService <ILogger <CliApplication> >(); _cliCommandExecutor = serviceProvider.GetRequiredService <ICliCommandExecutor>(); _rootSchemaAccessor = serviceProvider.GetRequiredService <IRootSchemaAccessor>(); _applicationLifetime = (CliApplicationLifetime)serviceProvider.GetRequiredService <ICliApplicationLifetime>(); }
/// <inheritdoc/> public async ValueTask <int> ExecuteAsync(IEnumerable <string> commandLineArguments, ICliCommandExecutor executor) { if (firstEnter && _configuration.StartupMode == typeof(InteractiveMode) && commandLineArguments.Any()) { await executor.ExecuteCommandAsync(commandLineArguments); } IEnumerable <string> interactiveArguments; try { interactiveArguments = await GetInputAsync(_metadata.ExecutableName); } catch (TaskCanceledException) { _logger.LogInformation("Interactive mode input cancelled."); return(ExitCodes.Error); } _console.ResetColor(); if (interactiveArguments.Any()) { await executor.ExecuteCommandAsync(interactiveArguments); _console.ResetColor(); } return(ExitCodes.Success); }
/// <inheritdoc/> public async ValueTask <int> ExecuteAsync(IEnumerable <string> commandLineArguments, ICliCommandExecutor executor) { if (firstEnter && _configuration.StartupMode == typeof(InteractiveMode) && commandLineArguments.Any()) { await executor.ExecuteCommandAsync(commandLineArguments); } IEnumerable <string> interactiveArguments = await GetInputAsync(_metadata.ExecutableName); _console.ResetColor(); if (interactiveArguments.Any()) { await executor.ExecuteCommandAsync(interactiveArguments); _console.ResetColor(); } return(ExitCodes.Success); }
public async ValueTask <int> ExecuteAsync(IEnumerable <string> commandLineArguments, ICliCommandExecutor executor) { await _console.Output.WriteLineAsync(nameof(ValidCustomMode)); int exitCode = await executor.ExecuteCommandAsync(commandLineArguments); _applicationLifetime.RequestStop(); await _console.Output.WriteLineAsync(nameof(ValidCustomMode) + "END"); return(exitCode); }
/// <inheritdoc/> public async ValueTask <int> ExecuteAsync(IEnumerable <string> commandLineArguments, ICliCommandExecutor executor) { int exitCode = await executor.ExecuteCommandAsync(commandLineArguments); _applicationLifetime.RequestStop(); return(exitCode); }