Shell option style

Energy.Core.Shell provides command-line option style definitions and argument classification.

OptionStyle

Energy.Core.Shell.OptionStyle controls how command-line options are recognized.

Energy.Core.Shell.OptionStyle style = new Energy.Core.Shell.OptionStyle
{
    Slash = true,    // /help
    Single = true,   // -h
    Double = true,   // --help
    Colon = true,    // /file:path
    Equal = true,    // /file=path
    Multiple = true, // -abc as -a -b -c
    Short = true,    // single letters only for single dash
};

bool isOption = style.IsOption("--help");
bool isArgument = style.IsArgument("input.txt");

Default style

Energy.Core.Shell.OptionStyle style = Energy.Core.Shell.OptionStyle.Default;

ArgumentList

Energy.Core.Shell.ArgumentList separates options from arguments.

string[] args = new[] { "--help", "-v", "input.txt" };
Energy.Core.Shell.ArgumentList list = Energy.Core.Shell.ArgumentList.Create(args, style);

foreach (string option in list.Options)
{
    Console.WriteLine("Option: {0}", option);
}

foreach (string argument in list.Arguments)
{
    Console.WriteLine("Argument: {0}", argument);
}

Parameter

Energy.Core.Shell.Parameter represents a typed parameter with an option name and a value.

Summary

Class Description
OptionStyle Option recognition rules.
ArgumentList Separated options and arguments.
Parameter Untyped parameter.
Parameter<T> Typed parameter.

See also

  • base-command for the fluent command-line parser.