From 59cb6ab3151d1de0700d641e1cc1c8f433286e17 Mon Sep 17 00:00:00 2001 From: Adam Ralph Date: Thu, 30 Dec 2021 20:14:45 +0100 Subject: [PATCH] remove Result type --- README.md | 5 ++--- SimpleExec/Command.cs | 6 +++--- SimpleExec/PublicAPI.Shipped.txt | 6 +----- SimpleExec/Result.cs | 25 ---------------------- SimpleExecTests/ConfiguringEnvironments.cs | 4 ++-- SimpleExecTests/ReadingCommands.cs | 20 ++++++++--------- 6 files changed, 18 insertions(+), 48 deletions(-) delete mode 100644 SimpleExec/Result.cs diff --git a/README.md b/README.md index 0b8ea38..62059da 100644 --- a/README.md +++ b/README.md @@ -42,9 +42,8 @@ await RunAsync("foo.exe", "arg1 arg2", "my-working-directory"); ### Read ```C# -// ReadAsync returns a CommandReadResult object with Out and Error properties representing standard out (stdout) and standard error (stderr) -var result1 = await ReadAsync("foo.exe"); -var result2 = await ReadAsync("foo.exe", "arg1 arg2", "my-working-directory"); +var (standardOutput1, standardError1) = await ReadAsync("foo.exe"); +var (standardOutput2, standardError2) = await ReadAsync("foo.exe", "arg1 arg2", "my-working-directory"); ``` ### Other optional arguments diff --git a/SimpleExec/Command.cs b/SimpleExec/Command.cs index c57b1c3..bcea851 100644 --- a/SimpleExec/Command.cs +++ b/SimpleExec/Command.cs @@ -157,12 +157,12 @@ public static async Task RunAsync( /// A to observe while waiting for the command to exit. /// /// A representing the asynchronous running of the command and reading of standard output (stdout) and standard error (stderr). - /// The task result is a representing the contents of standard output (stdout) and standard error (stderr). + /// The task result is a representing the contents of standard output (stdout) and standard error (stderr). /// /// /// The command exited with non-zero exit code. The exception contains the contents of standard output (stdout) and standard error (stderr). /// - public static async Task ReadAsync( + public static async Task<(string StandardOutput, string StandardError)> ReadAsync( string name, string args = "", string workingDirectory = "", @@ -215,7 +215,7 @@ public static async Task ReadAsync( #pragma warning restore CA1849 // Call async methods when in an async method return (handleExitCode?.Invoke(process.ExitCode) ?? false) || process.ExitCode == 0 - ? new Result(output, error) + ? (output, error) : throw new ExitCodeReadException(process.ExitCode, output, error); } diff --git a/SimpleExec/PublicAPI.Shipped.txt b/SimpleExec/PublicAPI.Shipped.txt index 6d42ce1..6822d17 100644 --- a/SimpleExec/PublicAPI.Shipped.txt +++ b/SimpleExec/PublicAPI.Shipped.txt @@ -9,10 +9,6 @@ SimpleExec.ExitCodeReadException SimpleExec.ExitCodeReadException.ExitCodeReadException(int exitCode, string! standardOutput, string! standardError) -> void SimpleExec.ExitCodeReadException.StandardError.get -> string! SimpleExec.ExitCodeReadException.StandardOutput.get -> string! -SimpleExec.Result -SimpleExec.Result.Result(string! standardOutput, string! standardError) -> void -SimpleExec.Result.StandardError.get -> string! -SimpleExec.Result.StandardOutput.get -> string! -static SimpleExec.Command.ReadAsync(string! name, string! args = "", string! workingDirectory = "", string? windowsName = null, string? windowsArgs = null, System.Action!>? configureEnvironment = null, System.Text.Encoding? encoding = null, System.Func? handleExitCode = null, string? standardInput = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! +static SimpleExec.Command.ReadAsync(string! name, string! args = "", string! workingDirectory = "", string? windowsName = null, string? windowsArgs = null, System.Action!>? configureEnvironment = null, System.Text.Encoding? encoding = null, System.Func? handleExitCode = null, string? standardInput = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<(string! StandardOutput, string! StandardError)>! static SimpleExec.Command.Run(string! name, string! args = "", string! workingDirectory = "", bool noEcho = false, string? windowsName = null, string? windowsArgs = null, string? echoPrefix = null, System.Action!>? configureEnvironment = null, bool createNoWindow = false, System.Diagnostics.ProcessWindowStyle windowStyle = System.Diagnostics.ProcessWindowStyle.Normal, System.Func? handleExitCode = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> void static SimpleExec.Command.RunAsync(string! name, string! args = "", string! workingDirectory = "", bool noEcho = false, string? windowsName = null, string? windowsArgs = null, string? echoPrefix = null, System.Action!>? configureEnvironment = null, bool createNoWindow = false, System.Diagnostics.ProcessWindowStyle windowStyle = System.Diagnostics.ProcessWindowStyle.Normal, System.Func? handleExitCode = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task! diff --git a/SimpleExec/Result.cs b/SimpleExec/Result.cs deleted file mode 100644 index 0cb1ef8..0000000 --- a/SimpleExec/Result.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace SimpleExec -{ - /// - /// The result of reading a command. - /// - public class Result - { - /// - /// Constructs an instance of a . - /// - /// The contents of standard output (stdout). - /// The contents of standard error (stderr). - public Result(string standardOutput, string standardError) => (this.StandardOutput, this.StandardError) = (standardOutput, standardError); - - /// - /// Gets the contents of standard output (stdout). - /// - public string StandardOutput { get; } - - /// - /// Gets the contents of standard error (stderr). - /// - public string StandardError { get; } - } -} diff --git a/SimpleExecTests/ConfiguringEnvironments.cs b/SimpleExecTests/ConfiguringEnvironments.cs index c6f729f..649a05c 100644 --- a/SimpleExecTests/ConfiguringEnvironments.cs +++ b/SimpleExecTests/ConfiguringEnvironments.cs @@ -12,10 +12,10 @@ public static class ConfiguringEnvironments public static async Task ConfiguringEnvironment() { // act - var result = await Command.ReadAsync("dotnet", $"exec {Tester.Path} environment", configureEnvironment: env => env["foo"] = "bar"); + var (standardOutput, _) = await Command.ReadAsync("dotnet", $"exec {Tester.Path} environment", configureEnvironment: env => env["foo"] = "bar"); // assert - Assert.Contains("foo=bar", result.StandardOutput, StringComparison.Ordinal); + Assert.Contains("foo=bar", standardOutput, StringComparison.Ordinal); } } } diff --git a/SimpleExecTests/ReadingCommands.cs b/SimpleExecTests/ReadingCommands.cs index 9e923a6..c927948 100644 --- a/SimpleExecTests/ReadingCommands.cs +++ b/SimpleExecTests/ReadingCommands.cs @@ -16,11 +16,11 @@ public static class ReadingCommands public static async Task ReadingACommandAsync(bool largeOutput) { // act - var result = await Command.ReadAsync("dotnet", $"exec {Tester.Path} hello world" + (largeOutput ? " large" : "")); + var (standardOutput, standardError) = await Command.ReadAsync("dotnet", $"exec {Tester.Path} hello world" + (largeOutput ? " large" : "")); // assert - Assert.Contains("hello world", result.StandardOutput, StringComparison.Ordinal); - Assert.Contains("hello world", result.StandardError, StringComparison.Ordinal); + Assert.Contains("hello world", standardOutput, StringComparison.Ordinal); + Assert.Contains("hello world", standardError, StringComparison.Ordinal); } [Theory] @@ -29,12 +29,12 @@ public static async Task ReadingACommandAsync(bool largeOutput) public static async Task ReadingACommandWithInputAsync(bool largeOutput) { // act - var result = await Command.ReadAsync("dotnet", $"exec {Tester.Path} hello world in" + (largeOutput ? " large" : ""), standardInput: "this is input"); + var (standardOutput, standardError) = await Command.ReadAsync("dotnet", $"exec {Tester.Path} hello world in" + (largeOutput ? " large" : ""), standardInput: "this is input"); // assert - Assert.Contains("hello world", result.StandardOutput, StringComparison.Ordinal); - Assert.Contains("this is input", result.StandardOutput, StringComparison.Ordinal); - Assert.Contains("hello world", result.StandardError, StringComparison.Ordinal); + Assert.Contains("hello world", standardOutput, StringComparison.Ordinal); + Assert.Contains("this is input", standardOutput, StringComparison.Ordinal); + Assert.Contains("hello world", standardError, StringComparison.Ordinal); } [Theory] @@ -43,11 +43,11 @@ public static async Task ReadingACommandWithInputAsync(bool largeOutput) public static async Task ReadingAUnicodeCommandAsync(bool largeOutput) { // act - var result = await Command.ReadAsync("dotnet", $"exec {Tester.Path} hello world unicode" + (largeOutput ? " large" : ""), encoding: new UnicodeEncoding()); + var (standardOutput, standardError) = await Command.ReadAsync("dotnet", $"exec {Tester.Path} hello world unicode" + (largeOutput ? " large" : ""), encoding: new UnicodeEncoding()); // assert - Assert.Contains("Pi (\u03a0)", result.StandardOutput, StringComparison.Ordinal); - Assert.Contains("Pi (\u03a0)", result.StandardError, StringComparison.Ordinal); + Assert.Contains("Pi (\u03a0)", standardOutput, StringComparison.Ordinal); + Assert.Contains("Pi (\u03a0)", standardError, StringComparison.Ordinal); } [Fact]