Skip to content

Command line parsing rules

Raymond Chen edited this page Mar 30, 2019 · 3 revisions

These are the command line parsing rules used by parser:

A command line parameter that begins with a hyphen (U+002D) selects an option as "current". Command line options are case-sensitive.

A command line parameter that begins with an at-sign (U+0040) specifies that the contents of the file whose name follows the at-sign (no space) should be read and treated as additional command line parameters. The contents of the file are parsed the same way as CommandLineToArgvW. This operation is recursive: If the file contains command line arguments that also begin with an at-sign, those files are also read and expanded.

A command line parameter that does not begin with any of the special characters above is appended to the values associated with the "current" command line option. If there is no "current" command line option, then an error is raised.

An error is raised if a command line option is invalid or does not meet the minimum or maximum requirements.

For example, the command line

-a 1 -b -c @x 2

is parsed as follows:

  • -a selects option a as current.
  • 1 is added to the values of the a option.
  • -b selects option b as current.
  • -c selects option c as current.
  • The contents of the file x are read. Assume that x consists of the line 3 -a.
    • 3 is added to the values of the c option.
    • -a selects option a as current.
  • 2 is added to the values of the a option.

The end result is that there are three options present:

  • a has values 1, 2.
  • b is present but has no values.
  • c has value 3.
  • d is not present.

Note that there is a distinction between a command line option that was never provided at all and a command line option that was provided with no values.

Clone this wiki locally