Remaining arguments gets reparsed and split on spaces
See original GitHub issueForked from spectresystems/spectre.cli#108 as requested
Scenario
My application wraps around execution of other applications so I need to pass all arguments as is, for example, this:
app run cmd -- /c "set && pause"
tells my app (app
) to run (run
) other application (cmd
) and pass "other arguments “as is” (/c "set && pause"
).
I can see though that single argument “set && pause” get’s reparsed as 3 “set”, “&&”, and “pause” (in context.Remaining.Raw
) and I lose all clues that it ever was a single one.
Code
class Program
{
static void Main(string[] args)
{
var testArgs = new[] {
"run",
"cmd",
"-e", "A=7",
"-e", "B=10",
"--",
"/c", "set && pause"
};
var app = new CommandApp();
app.Configure(config => config.AddCommand<RunCommand>("run"));
app.Run(testArgs);
}
}
public class RunCommand: Command<RunCommand.Settings>
{
public class Settings: CommandSettings
{
[CommandArgument(0, "<EXECUTABLE>")]
public string Executable { get; set; } = null!;
[CommandOption("-e <VAR=VAL>")]
public string[] Environment { get; set; } = Array.Empty<string>();
}
public override int Execute(CommandContext context, Settings settings)
{
Console.WriteLine(JsonConvert.SerializeObject(settings));
Console.WriteLine(JsonConvert.SerializeObject(new {
Parsed = context.Remaining.Parsed.ToArray(),
Raw = context.Remaining.Raw.ToArray()
}));
return 0;
}
}
Expected
{"Executable":"cmd","Environment":["A=7","B=10"]}
{"Parsed":[],"Raw":["/c","set && pause"]}
Actual
{"Executable":"cmd","Environment":["A=7","B=10"]}
{"Parsed":[],"Raw":["/c","set","&&","pause"]}
(See: Raw
array, expected 2 arguments, received 4 arguments)
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (12 by maintainers)
Top Results From Across the Web
Split a string containing json w/spaces into arguments
I am implementing a command shell using cmd2, and I wanted to setup a few commands that allows a user to type in...
Read more >shell - Is it possible for a program to get number of spaces ...
In general, no. Command line parsing is done by the shell which does not make the unparsed line available to the called program....
Read more >Why does xargs split on spaces even with -0?
No, it doesn't split on spaces. The shell splits the output of the $(…) expansion on spaces, and xargs can do absolutely nothing...
Read more >String.prototype.split() - JavaScript - MDN Web Docs - Mozilla
The split() method of String values takes a pattern and divides this string into an ordered list of substrings by searching for the...
Read more >Split text by empty spaces
Hello all,. I'm trying to split a text (e.g. "MR. JOHN SMITH" or "MRS. JANE AUSTIN SMITH") into chunks in order to be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@MiloszKrajewski Btw, I notice that you’re trying to parse the form
-e FOO=BAR -e BAZ=QUX
. This is already supported. Just set the type of yourEnvironment
property toILookup<string, string>
, and it will be mapped automatically.The types
ILookup<string, string>
,IDictionary<string, string>
andIReadOnlyDictionary<string, string>
will work here, but the two latter will, of course, not support multiple values for the same key.Yes it is what I would expect. Although… I by accident discovered unrelated bug (I managed to freeze/infinite loop parser). I’ll create new issue (#186)