public static async ValueTask <(int exitCode, MemoryStreamWriter stdOut, MemoryStreamWriter stdErr)> BuildAndRunTestAsync(this CliApplicationBuilder applicationBuilder, ITestOutputHelper testOutput, string commandLine, IReadOnlyDictionary <string, string> environmentVariables, bool containsExecutable = false, bool isInputRedirected = true, string?input = null) { var(console, stdIn, stdOut, stdErr) = VirtualConsole.CreateBufferedWithInput(isInputRedirected: isInputRedirected); CliApplication application = applicationBuilder.UseConsole(console) .Build(); if (input is not null) { stdIn.WriteString(input.TrimEnd('\r') + "\rexit\r"); } int exitCode = await application.RunAsync(commandLine, environmentVariables, containsExecutable); testOutput.WriteLine("Exit Code: {0}", exitCode); testOutput.Print(stdOut, stdErr); return(exitCode, stdOut, stdErr); }
public static async Task Main(string[] args) { var assembly = Assembly.GetExecutingAssembly(); Provider = MakeServiceProvider(); var validationResult = await Provider.ValidateOptionsAsync(assembly); if (!validationResult.IsSuccessful) { Console.WriteLine($"Config Validation failed: {validationResult.Reason}"); return; } InitializeServices(); Application = new CliApplicationBuilder() .AddCommandsFromThisAssembly() .UseTypeActivator(Provider.GetService) .SetVersion("v0.8.0") .SetExecutableName("ChiaPool") .SetTitle("ChiaPool CLI") .Build(); await Application.RunAsync(); }
public static async Task Main(string[] args) { Provider = MakeServiceProvider(); Application = new CliApplicationBuilder() .AddCommandsFromThisAssembly() .UseTypeActivator(Provider.GetService) .Build(); await Application.RunAsync(); }
public static async ValueTask <(int exitCode, MemoryStreamWriter stdOut, MemoryStreamWriter stdErr)> BuildAndRunTestAsync(this CliApplicationBuilder applicationBuilder, ITestOutputHelper testOutput, IReadOnlyList <string> commandLineArguments, IReadOnlyDictionary <string, string> environmentVariables, bool isInputRedirected = true) { var(console, stdOut, stdErr) = VirtualConsole.CreateBuffered(isInputRedirected: isInputRedirected); CliApplication application = applicationBuilder.UseConsole(console) .Build(); int exitCode = await application.RunAsync(commandLineArguments, environmentVariables); testOutput.WriteLine("Exit Code: {0}", exitCode); testOutput.Print(stdOut, stdErr); return(exitCode, stdOut, stdErr); }
public async Task Console_color_extensions_should_work_after_colors_reset() { // Arrange var builder = new CliApplicationBuilder().AddCommand <WithColorsAndResetCommand>(); var(console, stdOut, stdErr) = VirtualAnsiConsole.CreateBuffered(isInputRedirected: false, isOutputRedirected: false, isErrorRedirected: false); CliApplication application = builder.UseConsole(console) .Build(); int exitCode = await application.RunAsync("colors-with-reset", new Dictionary <string, string>()); _output.WriteLine("Exit Code: {0}", exitCode); _output.Print(stdOut, stdErr); // Assert exitCode.Should().Be(ExitCodes.Success); stdOut.GetString().Should().Contain(WithColorsAndResetCommand.ExpectedOutputText); stdErr.GetString().Should().BeNullOrWhiteSpace(); }
public async Task RunAsync_Test() { // Arrange var command = new TestCommand(); var expectedExitCode = await command.ExecuteAsync(); var commandOptionParser = new CommandOptionParser(); var typeProvider = new TypeProvider(typeof(TestCommand)); var commandOptionConverter = new CommandOptionConverter(); var commandResolver = new CommandResolver(typeProvider, commandOptionConverter); var application = new CliApplication(commandOptionParser, commandResolver); // Act var exitCodeValue = await application.RunAsync(); // Assert Assert.That(exitCodeValue, Is.EqualTo(expectedExitCode.Value), "Exit code"); }