Command line handling specifications

This page details the supported features and expected behaviors of the command line parsers implemented in this project.

For a synthesis of what is currently supported in the different parsers, see the specification compliance page.

The words written in bold-monospace are keywords to identify a feature, a behavior or a parser message. These keywords are used as references in the specification compliance page and in unit tests.

Options

Short option names

A short option name (son) is an option name of only one character. On the command line, it have to be prefixed by a single hyphen-minus character '-'

program_name -o

For single and multiple arguments options, the first option argument can be the next command line argument (son-arg-separated)

program_name -o "option argument"

or can be combined to the option letter (son-arg-combined)

program_name -oArgumentWithoutSpace
program_name -o"Argument With Space"
rsync -lprtve bash

see man rsync

Long option names

A long option name (lon) is an option name of two or more characters. On the command line, it have to be prefixed by a double hyphen-minus character '--'

program_name --option

For single and multiple arguments options, the first option argument can be the next command line argumen (lon-separated)t

program_name --option "option argument"

or can be combined to the option name after a equal sign '=' (lon-combined)

program_name --option=ArgumentWithoutSpace
program_name --option="Argument With Space"

Option name aliasing

The program interface definition XSD scheam requires the following rules:

So, a subcommand option name may alias a program-scope option name (on-aliasing).

In this case, the option will be interpreted as the program-scope option if it appears before the subcommand name (on-aliasing-before-sc).

program --aliased-option subcommand --subcommand-option value1 value2

Or as the subcommand option if it appears after the subcommand name (on-aliasing-after-sc).

program subcommand --aliased-option --subcommand-option value1 value2

Switches

Single argument option

Multiple arguments option

Option group

A option group (grp) offers a way to group several related option. This kind of option does not have any particular meaning for a command line parser unless the group is set as a mutually exclusive option group (xgrp)

Mutually exclusive option group

An option group defined as exclusive adds the following rules

Sub command

Markers

Markers are special command line arguments that change the parser behavior. They does not appear in positional argument (value) list nor in single/multiple argument option argument list.

'End-of-options' marker

program subcommand -a --option arg1 -- value1 --even-this-is-a-value

There is no exception to this behavior.

'End of arguments' marker

to stop considering the following command line arguments as arguments of the current multiple argument option.

program subcommand --multiarg-option arg1 arg2 - value1 value2

String literals

The program interface definition file is language-independent, so string literals specified in node such as <prg:documentation />, <prg:default /> and <prg:option/> will not be evaluated even if the language allow this feature.

For example, specifying <prg:default>$(pwd)</prg:default> as the default value of a single argument option will NOT be dynamically evaluated by a UNIX shell program.

Escaping and disambiguation

If a positional argument is not an option but starts with a hyphen-minus character, the positional argument will be misinterpreted as an option name.

program subcommand --switch-option -positional_argument_which_is_not_an_option

To avoid this invalid behavior, the hyphen-minus character have to be escaped by the user using the backslash character (escape-markers).

program subcommand --switch-option \\-positional_argument_which_is_not_an_option
# or
program subcommand --switch-option "\-positional_argument_which_is_not_an_option"

The following markers can be escaped

The parser will have to unescape (escape-unescape) any command line argument starting with '\-" before storing it as an option argument or a positional argument. In the example above, the second argument of the command line will have to be interpreted as the positional argument '-positional_argument_which_is_not_an_option'

Argument validation

Post processing phase

Error handling

The general behavior of command line parsers is to go as far as they can to provide as much informations as possible to the user in case of error.

See also



The program interface definition framework