-
-
Notifications
You must be signed in to change notification settings - Fork 273
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
Add arguments as explicit key-value pairs with limited escaping #263
Comments
Hi. I had been thinking before about adding a high-level API for setting options, but I ultimately never committed to it because there's too many different styles and approaches for receiving command-line arguments. Even if the parsing between two programs looks similar, there are still often nuanced differences (e.g. I think in this scenario, I prefer the approach you described as the alternative (exposing |
It looks like you also didn't include this approach in the list, I'm curious if this works: var command = Cli.Wrap("google-chrome")
.WithArguments(args =>
{
args.Add("--param-name=Parameter Value").Add("Argument Value");
}); Should result in:
...which, might work. |
That's a good point, actually, I don't think I've tried that approach. I'll try that and see if the tools I'm using handle the "quoted name and value" scenario. |
@agc93 have you had the chance to try it? |
I have, and it did work with Chrome, but did not work with one of the other tools I was trying to launch (which gets launched through Personally, I think exposing |
Details
This may be a bit too niche to include, but I'll ask anyway.
Context
Some applications have unintuitive command-line behaviour, where
executable --option param argument
andexecutable --option=param argument
have different behaviours. For applications like this, using CliWrap can be a bit trickier since it (as far as I can tell) requires adding options of the format--option=param
as a single argument and handling escaping yourself.Request
I'd like an addition to the arguments API to add a key-value pair where CliWrap still does its normal intelligent escaping behaviour for the "value" of the pair but does not escape the whole argument.
Scenario
I want to end up with a command like the following:
google-chrome --param-name="Parameter Value" "Argument Value"
while retaining as much of CliWrap's (incredibly useful!) automatic escaping behaviour as possible.Current behaviour:
Adding Name and Value separately
Adding the parameter name and value as separate values:
results in the incorrect result of
google-chrome --param-name "Parameter Value" "Argument Value"
(no=
between the parameter name and value will upset Chrome).Adding the name and value as a single argument
results in the incorrect result of
google-chrome "--param-name=\"Parameter Value\"" "Argument Value"
, since CliWrap also escapes the parameter name.Adding the name and value as a single argument, with escaping disabled
results in the correct command, but I now have to handle correctly quoting
Parameter Value
myself rather than CliWrap handling it.Example of behaviour
google-chrome --profile-directory="Display Name" "https://domain.tld?key=\"value\""
args.Add(["--profile-directory", "Display Name"]).Add("https://domain.tld?key=\"value\"")
google-chrome --profile-directory "Parameter Value" "https://domain.tld?key=\"value\""
=
args.Add("--profile-directory=\"Display Name\"").Add("https://domain.tld?key=\"value\"")
google-chrome "--profile-directory=\"Display Name\"" "https://domain.tld?key=\"value\""
--profile-directory
) also quoted, option value double quotedargs.Add("--profile-directory=\"Display Name\"", false).Add("https://domain.tld?key=\"value\"")
google-chrome --profile-directory="Display Name" "https://domain.tld?key=\"value\""
Ideal Behaviour
What would be nice is an API (maybe a new overload) to add values to the argument list as specifically key-value pairs where CliWrap will still intelligently escape the value.
For example, something like:
would allow me to simply use:
to get the desired behaviour without having to re-implement CliWrap's
Escape
functionality.Alternatives
Alternatively, to let consumers recreate behaviour like this on their own, could it be worth opening up CliWrap's
ArgumentsBuilder.Escape
method to bepublic
so that consumers can add arguments usingEscape()
without having to copy-paste it (my current solution)Checklist
The text was updated successfully, but these errors were encountered: