Skip to content
This repository has been archived by the owner on Jun 27, 2022. It is now read-only.
Craig Fowler edited this page Jan 27, 2017 · 2 revisions

Command-line parameter reader

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:

  1. Create a builder
  2. Use that builder to register the expected parameters
  3. Build a parser instance
  4. Use the parser to parse your parameters

Parameter types

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.

Long and short parameter names

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.

Clone this wiki locally