Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OSOE-351: Adding params-using CliProgram.GetCommand() overload, StringExtensions docs #224

Merged
merged 4 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Lombiq.HelpfulLibraries.Cli/CliProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public class CliProgram

public CliProgram(string command) => _command = command + OperatingSystemHelper.GetExecutableExtension();

/// <summary>
/// Creates a <see cref="Command"/> object based on the passed <paramref name="arguments"/>.
/// </summary>
public Command GetCommand(params object[] arguments) =>
GetCommand(arguments.ToList());

/// <summary>
/// Creates a <see cref="Command"/> object based on the passed <paramref name="arguments"/>.
/// </summary>
Expand Down Expand Up @@ -70,6 +76,27 @@ public async Task ExecuteAsync(
public Task ExecuteAsync(CancellationToken token, params object[] arguments) =>
ExecuteAsync(arguments, additionalExceptionText: null, token);

/// <summary>
/// Calls the command specified in the constructor with the provided arguments, and returns the standard output as a
/// string. If the process doesn't succeed or outputs to the standard error stream then an exception is thrown.
/// </summary>
/// <param name="token">Passed into the CliWrap <see cref="Command"/>.</param>
/// <param name="arguments">
/// The arguments passed to the command. If an item is not a <see langword="string"/>, then it's converted using the
/// <see cref="CultureInfo.InvariantCulture"/> formatter.
/// </param>
/// <returns>The standard output as a string.</returns>
/// <exception cref="InvalidOperationException">
/// <para>Thrown if the command fails or outputs to the error stream. The format is like this:</para>
/// <code>
/// The {command} {arguments} command failed with the output below.
/// {additional exception text}
/// {standard error output}
/// </code>
/// </exception>
public Task<string> ExecuteAndGetOutputAsync(CancellationToken token, params object[] arguments) =>
ExecuteAndGetOutputAsync(arguments, additionalExceptionText: null, token);

/// <summary>
/// Calls the command specified in the constructor with the provided arguments, and returns the standard output as a
/// string. If the process doesn't succeed or outputs to the standard error stream then an exception is thrown.
Expand Down
7 changes: 4 additions & 3 deletions Lombiq.HelpfulLibraries.Common/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,15 @@ public static string ReplaceOrdinalIgnoreCase(this string text, string oldValue,
text.Replace(oldValue, newValue ?? string.Empty, StringComparison.OrdinalIgnoreCase);

/// <summary>
/// A shortcut for <c>string.Equals(string, StringComparison.Ordinal)</c>.
/// Use simple <see cref="string"/> equality check with <c>=</c> instead, since it already uses ordinal string
/// comparison.
/// </summary>
[Obsolete("The string equals operator already uses ordinal string comparison.")]
public static bool EqualsOrdinal(this string text, string? value) =>
throw new NotSupportedException();

/// <summary>
/// A shortcut for <c>string.Contains(string, StringComparison.Ordinal)</c>.
/// Use <c>string.Contains(string)</c> instead, since it already uses ordinal string comparison..
/// </summary>
[Obsolete("The string.Contains(value) member method already uses ordinal string comparison.")]
public static bool ContainsOrdinal(this string text, string value) =>
Expand Down Expand Up @@ -168,7 +169,7 @@ public static bool EndsWithOrdinal(this string text, string value) =>
text.EndsWith(value, StringComparison.Ordinal);

/// <summary>
/// A shortcut for <c>string.Replace(string, string, StringComparison.Ordinal)</c>.
/// Use <c>string.Replace(string, string) instead, since it already uses ordinal string comparison.</c>.
/// </summary>
[Obsolete("The string.Replace(oldValue, newValue) member method already uses ordinal string comparison.")]
public static string ReplaceOrdinal(this string text, string oldValue, string? newValue = "") =>
Expand Down