-
Notifications
You must be signed in to change notification settings - Fork 0
Home
The command-line parameter reader/parser provides facility to read parameters passed to a command-line/console application. There are two variants of the reader available:
There are two variants of the parser/reader available. Most applications will want to use the generic reader. The generic reader creates an instance of a C♯ class of your own design (a POCO) and sets the values of that class' properties accordingly from the command-line parameters.
In scenarios where this is not suitable, there is a non-generic reader available. This is useful when the complete list of expected parameters cannot be known at compile-time. Consider a modular application in which add-on modules may expand upon the accepted parameters. The non-generic reader outputs a type which exposes the parsed parameters using arbitrary identifiers.
Regardless of which mechanism you choose, the general procedure for creating and using a parser is the same:
- Create a builder
- Use that builder to register the expected parameters
- Build a parser instance
- Use the parser to parse your parameters
The command-line reader supports two core types of paramaters:
- Flag parameters which translate to true or false
- Value parameters which accept an associated string value
Read more about parameter types on the corresponding wiki page.
The command-line reader supports two mechanisms of naming parameters:
-
Long names which are prefixed by two dashes, for example
--my-long-name
-
Short names which are always only a single character, and prefixed by a single dash, for example
-l
Each parameter may be registered with as many long/short names as you desire, although it must have at least one name. Read more about parameter long and short names on the corresponding wiki page.