Skip to content

Commit aae1382

Browse files
authored
Expose ArgumentsBuilder.Escape(...) (#265)
1 parent 5787f27 commit aae1382

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

CliWrap/Builders/ArgumentsBuilder.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,16 @@ public ArgumentsBuilder Add(IEnumerable<IFormattable> values, bool escape) =>
142142

143143
public partial class ArgumentsBuilder
144144
{
145-
private static string Escape(string argument)
145+
/// <summary>
146+
/// Escapes special characters (spaces, slashes, and quotes) in the specified string, ensuring that the output
147+
/// is correctly interpreted as a single argument when passed to a command-line application.
148+
/// </summary>
149+
/// <remarks>
150+
/// In most cases, you should not need to use this method, as <see cref="ArgumentsBuilder" /> already escapes
151+
/// arguments automatically. This method is provided for advanced scenarios where you need to escape arguments
152+
/// manually.
153+
/// </remarks>
154+
public static string Escape(string argument)
146155
{
147156
// Implementation reference:
148157
// https://github.com/dotnet/runtime/blob/9a50493f9f1125fda5e2212b9d6718bc7cdbc5c0/src/libraries/System.Private.CoreLib/src/System/PasteArguments.cs#L10-L79

Readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,10 @@ var cmd = Cli.Wrap("git")
219219
> This method expects all arguments to be correctly escaped and formatted ahead of time — which can be cumbersome to do yourself.
220220
> Formatting errors may result in unexpected bugs and security vulnerabilities.
221221
222+
> **Note**:
223+
> There are some [obscure scenarios](https://github.com/Tyrrrz/CliWrap/issues/263), where you may need to assemble the command-line arguments yourself.
224+
> In such cases, you can use the `ArgumentsBuilder.Escape(...)` method to escape individual arguments manually.
225+
222226
#### `WithWorkingDirectory(...)`
223227

224228
Sets the working directory of the child process.

0 commit comments

Comments
 (0)