Skip to content

Commit

Permalink
asd
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Nov 23, 2023
1 parent 3487a23 commit d8a4ae1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
21 changes: 19 additions & 2 deletions CliWrap.Magic/CliWrapExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,26 @@ out string standardError
standardError = result.StandardError;
}

/// <summary>
/// Executes the command with magic.
/// </summary>
public static CommandTask<MagicalCommandResult> ExecuteMagicalAsync(this Command command) =>
command
.ExecuteBufferedAsync()
.Select(
r =>
new MagicalCommandResult(
r.ExitCode,
r.StartTime,
r.ExitTime,
r.StandardOutput,
r.StandardError
)
);

/// <summary>
/// Executes the command with buffering and returns the awaiter for the result.
/// </summary>
public static TaskAwaiter<BufferedCommandResult> GetAwaiter(this Command command) =>
command.ExecuteBufferedAsync().GetAwaiter();
public static TaskAwaiter<MagicalCommandResult> GetAwaiter(this Command command) =>
command.ExecuteMagicalAsync().GetAwaiter();
}
18 changes: 17 additions & 1 deletion CliWrap.Magic/MagicalCommandResult.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
using CliWrap.Buffered;
using System;
using CliWrap.Buffered;

namespace CliWrap.Magic;

/// <summary>
/// Result of a command execution, with buffered text data from standard output and standard error streams.
/// </summary>
public class MagicalCommandResult : BufferedCommandResult
{
/// <summary>
/// Initializes an instance of <see cref="MagicalCommandResult" />.
/// </summary>
public MagicalCommandResult(
int exitCode,
DateTimeOffset startTime,
DateTimeOffset exitTime,
string standardOutput,
string standardError
)
: base(exitCode, startTime, exitTime, standardOutput, standardError) { }

/// <summary>
/// Converts the result to an integer value that corresponds to the <see cref="CommandResult.ExitCode" /> property.
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions CliWrap.Magic/Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,19 @@ public static IDisposable Environment(string name, string? value)
public partial class Tools
{
/// <summary>
/// Default standard input pipe used for commands created by <see cref="Command" />.
/// Default standard input pipe used for commands created by <see cref="Command(string)" />.
/// </summary>
public static PipeSource DefaultStandardInputPipe { get; set; } =
PipeSource.FromStream(Console.OpenStandardInput());

/// <summary>
/// Default standard output pipe used for commands created by <see cref="Command" />.
/// Default standard output pipe used for commands created by <see cref="Command(string)" />.
/// </summary>
public static PipeTarget DefaultStandardOutputPipe { get; set; } =
PipeTarget.ToStream(Console.OpenStandardOutput());

/// <summary>
/// Default standard error pipe used for commands created by <see cref="Command" />.
/// Default standard error pipe used for commands created by <see cref="Command(string)" />.
/// </summary>
public static PipeTarget DefaultStandardErrorPipe { get; set; } =
PipeTarget.ToStream(Console.OpenStandardError());
Expand Down

0 comments on commit d8a4ae1

Please sign in to comment.