Skip to content

Commit

Permalink
Expose ArgumentsBuilder.Escape(...) (#265)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz authored Dec 6, 2024
1 parent 5787f27 commit aae1382
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
11 changes: 10 additions & 1 deletion CliWrap/Builders/ArgumentsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,16 @@ public ArgumentsBuilder Add(IEnumerable<IFormattable> values, bool escape) =>

public partial class ArgumentsBuilder
{
private static string Escape(string argument)
/// <summary>
/// Escapes special characters (spaces, slashes, and quotes) in the specified string, ensuring that the output
/// is correctly interpreted as a single argument when passed to a command-line application.
/// </summary>
/// <remarks>
/// In most cases, you should not need to use this method, as <see cref="ArgumentsBuilder" /> already escapes
/// arguments automatically. This method is provided for advanced scenarios where you need to escape arguments
/// manually.
/// </remarks>
public static string Escape(string argument)
{
// Implementation reference:
// https://github.com/dotnet/runtime/blob/9a50493f9f1125fda5e2212b9d6718bc7cdbc5c0/src/libraries/System.Private.CoreLib/src/System/PasteArguments.cs#L10-L79
Expand Down
4 changes: 4 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ var cmd = Cli.Wrap("git")
> This method expects all arguments to be correctly escaped and formatted ahead of time — which can be cumbersome to do yourself.
> Formatting errors may result in unexpected bugs and security vulnerabilities.
> **Note**:
> There are some [obscure scenarios](https://github.com/Tyrrrz/CliWrap/issues/263), where you may need to assemble the command-line arguments yourself.
> In such cases, you can use the `ArgumentsBuilder.Escape(...)` method to escape individual arguments manually.
#### `WithWorkingDirectory(...)`

Sets the working directory of the child process.
Expand Down

0 comments on commit aae1382

Please sign in to comment.