Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

Conventions

Bevan Arps edited this page Nov 23, 2014 · 7 revisions

Options are declared by writing methods that comply with the appropriate convention (see below).

Each option has both a short form starting with a single dash - (e.g.: -f, -h or -rs) and a long form starting with a double dash -- (e.g.: --find, --help or --report-status). These names are derived from the names of the implementing methods (e.g.: Find(), Help() or ReportStatus()).

Switches

Switches are command line options that appear by themselves to activate a particular feature. Common switches include --help, --quiet and --verbose.

To define a switch, declare a method with no return and no parameters. Give it a [Description] attribute to document what the switch does.

For example, this method:

[Description("Show help listing all available options")]
public void Help();

will give the options -h and --help.

Parameters

Parameters are command line options that require a parameter value. Common parameters include --find <keyword>, --log <file>, --username <user> and --output <file>.

To define a simple parameter, declare a method with no return and one parameter. Again, give it a [Description] attribute to document what the option does.

For example, this method:

[Description("Specify the username to use for the connection.")]
public void Username(string user) { ... }

will give the options -u <user> and --username <user>.

The name of the parameter will be included in the help generated for the parameter; I suggest you ensure it has a meaningful name.

The type of the parameter need not be string - if you use any other type, the processor will try to find a sensible conversion to apply automatically.

By default, parameters can only be specified once. If you want a repeatable parameter, define your method with an IEnumerable<T> parameter like this:

[Description("Find files that match a wildcard")]
public void Find(IEnumerable<string> wildcard);

You can use IList<T> or List<T> if you prefer. The method will be called once, with a sequence of all the values specified on the command line.

Modes

Modes are different functions, different operations supported by the application - a common approach in more complex console applications. Different modes may have completely different sets of parameters.

To define a mode, declare a method with no parameters that returns a new driver - this driver will replace the existing driver, with the parameters and switches on the new driver superseding those of the former. As for switches and parameters, add a [Description] attribute to document what the mode provides.

[Description("Run diagnostics to test the server is operational.")]
public void AutomatedSmokeTest(IEnumerable<string> wildcard);

This defines a single mode that accessible as automated-smoke-test.

See Mode Support for more information.

Clone this wiki locally