Skip to content

CommandLineStringSplitter does not conform to "standard" quote escaping rules #1758

@jonsequitur

Description

@jonsequitur

The CommandLineStringSplitter provides a way to split a string into a string[] and is intended to conform to the way that strings are split on the command line.

It has two primary use cases:

  • Testing. Testing your parser using Parse(string[] args) or Invoke(string[] args) can be error prone because it requires people to make assumptions about how a command line will actually be split when your app is started, and the actual rules are not always intuitive.
  • Completions. CommandLineStringSplitter is critical for completions, since the only way to capture the text on the command line from within the launched .NET application is to pass it in as a complete string from the shim shell script and then split it into the equivalent string[] args array that Main receives.

Various shells will exhibit different behaviors here due to different quote escaping rules, so the user's experience of this splitting logic might not match up with a single implementation of CommandLineStringSplitter. Because of this, and to eventually provide higher fidelity for the completions experience on different shells in the presence of escapes on the command line, it might be useful to provide multiple implementations over time and we should consider anticipating that need in the API design now.

Resources

Related


For the purposes of illustration in examples below, I'll be using the following program to confirm behaviors that differ among various shells:

Console.WriteLine("---- DEFAULT SPLIT            ---");

foreach (var arg in args)
{
    Console.WriteLine(arg);
}

Console.WriteLine("---- Environment.CommandLine ----");

Console.WriteLine(Environment.CommandLine);

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions