-
Notifications
You must be signed in to change notification settings - Fork 2
Syntax
Each "word" on a command line is a token. The rules of a specific command line application determine whether these tokens are parsed as verbs, options, values, etc. This library follow getopt syntax with addition of verbs
preceding options and values.
myapp <VERBS> <OPTIONS> <VALUES>
myapp <VERB> [<VERB> ...] [--|-<OPTION> [<OPTION_VALUE>] ...] [--] [<VALUE> ...]
A verb is a token that corresponds to an action that the app will perform. The simplest command line applications have only a one command. In this case verb token could be omitted by specifying a CommandLineConfiguration.DefaultVerbName
when configuring the CommandLine
.
Verb or verbs must come before variants and meanings like this:
> myapp compress -f -x c:/myfile.txt
^------^
VERB
Several verbs can follow each other to achieve more complex APIs:
> myapp disk scan --disk 1
^--^
VERB ^--^
SUB-VERB
An option is a named parameter that can be passed to a verb. In POSIX command lines, you'll often see options represented like this:
> myapp --int-option 123
^---------------^
OPTION
In Windows command lines, you'll often see options represented like this:
> myapp /int-option 123
^-------------^
OPTION
Both syntaxes are valid for this library.
In both POSIX and Windows command lines, it's common for some options to have short names (aka aliases). In the following help example, -v
and --verbose
are aliases for the same option:
> myapp --verbose
> myapp -v
Short named options could be composed together without delimiter. Last one option also could have value like this:
> myapp /?
-v, --verbose Show verbose output
-d, --debug nable debug mode
-w, --warning-level Set warning level
> myapp -dvw
> myapp -dvw=123
Use AliasAttribute
on method's parameter to declare alias.
In addition to a space delimiting an option from its argument, =
is also could be used. The following command lines are equivalent:
> myapp --integer-option 123
> myapp --integer-option=123
> myapp -i=123
A value is an additional tokens after options. They can be any arbitrary string:
> myapp --integer-option 123 c:/myfile.txt d:/myfile.txt
^---------VALUES----------^
There is special option ending token --
which is used to delimit options from values:
> myapp -- -cmd /? this is value
^------VALUES-------^