Command line arguments

Brand new class Energy.Base.Command.Arguments appeared here to ease implement command line options for everybody.

This class is build with Named Parameter Idiom design pattern.

Argument parsing mechanism was inspired by excelent npm package yargs for JavaScript.

var argv = new Energy.Base.Command.Arguments(args)
    .Alias("?", "help")
    .Alias("q", "quiet")
    .Alias("i", "input")
    .Alias("o", "input")
    .Help("input", "Input file")
    .Help("output", "Output file")

if (!argv["help"].Empty)


Energy.Base.Command.Arguments(string[] args)
Energy.Base.Command.Arguments(string line)

You can still add argument line later.



Add command line parameter that will consume one or more trailing arguments and provide them as values.

If you set count to 0, it will become switch (flag).

Arguments Parameter(string name, int count)

Add command line parameter that will consume one next trailing argument and provide it as value.

Arguments Parameter(string name)

Special one.

Treat all unknown options as parametered.

Arguments Parameter()


Add single command line switch option, known also as flag. Like “-v”, or “–version”.

Arguments Switch(string name)

Special one.

Treat all unknown options as simple switches.

Arguments Switch()


Add arguments from text line.

Arguments are divided by any whitespace character.

Arguments may use double quote (”) character to include whitespace, and multiple quoting is allowed within one argument.

For example: C:”Documents and settings””Program Files”will be considered as one argument.

Arguments Line(string line)


Set strict mode.

When strict mode is set, exception will be thrown on unrecognized option name.

Arguments Strict(bool strict)


Allow usage of slash options (starting with “/”).

Allows to use DOS style options like “/?”.

It’s RSX-11 (and other similar DEC systems), through CP/M to MS-DOS legacy.

Should be avoided probably.

Arguments Slash(bool slash)


Allow usage of short options (starting with “-”).

Turned on as default.

Arguments Short(bool enable)


Allow usage of long options (starting with “–”).

Turned on as default.

Arguments Long(bool enable)


Add alias to parameter key.

Arguments Alias(string alias, string name)


Add help description for parameter key.

Arguments Help(string name, string description)


Probably most important function here.

Parse arguments and set values for options.

Arguments Parse()

Parameterless method will parse arguments set by constructor or modified later.

When calling with parameters, arguments to be parsed will only be taken from invoker.

Arguments Parse(string line)
Arguments Parse(string[] args)