Skip to content

Commit

Permalink
Merge pull request #400 from adamralph/bye-result-9.0
Browse files Browse the repository at this point in the history
remove Result type
  • Loading branch information
adamralph authored Dec 30, 2021
2 parents 2feb5b0 + 59cb6ab commit 4c76dbe
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 48 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions SimpleExec/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ public static async Task RunAsync(
/// <param name="cancellationToken">A <see cref="CancellationToken"/> to observe while waiting for the command to exit.</param>
/// <returns>
/// A <see cref="Task{TResult}"/> representing the asynchronous running of the command and reading of standard output (stdout) and standard error (stderr).
/// The task result is a <see cref="Result"/> representing the contents of standard output (stdout) and standard error (stderr).
/// The task result is a <see cref="ValueTuple{T1, T2}"/> representing the contents of standard output (stdout) and standard error (stderr).
/// </returns>
/// <exception cref="ExitCodeReadException">
/// The command exited with non-zero exit code. The exception contains the contents of standard output (stdout) and standard error (stderr).
/// </exception>
public static async Task<Result> ReadAsync(
public static async Task<(string StandardOutput, string StandardError)> ReadAsync(
string name,
string args = "",
string workingDirectory = "",
Expand Down Expand Up @@ -215,7 +215,7 @@ public static async Task<Result> 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);
}

Expand Down
6 changes: 1 addition & 5 deletions SimpleExec/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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<System.Collections.Generic.IDictionary<string!, string!>!>? configureEnvironment = null, System.Text.Encoding? encoding = null, System.Func<int, bool>? handleExitCode = null, string? standardInput = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task<SimpleExec.Result!>!
static SimpleExec.Command.ReadAsync(string! name, string! args = "", string! workingDirectory = "", string? windowsName = null, string? windowsArgs = null, System.Action<System.Collections.Generic.IDictionary<string!, string!>!>? configureEnvironment = null, System.Text.Encoding? encoding = null, System.Func<int, bool>? 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<System.Collections.Generic.IDictionary<string!, string!>!>? configureEnvironment = null, bool createNoWindow = false, System.Diagnostics.ProcessWindowStyle windowStyle = System.Diagnostics.ProcessWindowStyle.Normal, System.Func<int, bool>? 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<System.Collections.Generic.IDictionary<string!, string!>!>? configureEnvironment = null, bool createNoWindow = false, System.Diagnostics.ProcessWindowStyle windowStyle = System.Diagnostics.ProcessWindowStyle.Normal, System.Func<int, bool>? handleExitCode = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
25 changes: 0 additions & 25 deletions SimpleExec/Result.cs

This file was deleted.

4 changes: 2 additions & 2 deletions SimpleExecTests/ConfiguringEnvironments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
20 changes: 10 additions & 10 deletions SimpleExecTests/ReadingCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down

0 comments on commit 4c76dbe

Please sign in to comment.