Class CommandOption
- Namespace
- McMaster.Extensions.CommandLineUtils
- Assembly
- McMaster.Extensions.CommandLineUtils.dll
Represents one or many command line option that is identified by flag proceeded by '-' or '--'. Options are not positional. Compare to CommandArgument.
public class CommandOption
- Inheritance
-
objectCommandOption
- Derived
- Extension Methods
Constructors
CommandOption(string, CommandOptionType)
Initializes a new CommandOption.
public CommandOption(string template, CommandOptionType optionType)
Parameters
templatestringThe template string. This is parsed into ShortName and LongName.
optionTypeCommandOptionTypeThe option type.
Properties
DefaultValue
The default value of the option.
public string? DefaultValue { get; set; }
Property Value
Description
A description of this option to show in generated help text.
public string? Description { get; set; }
Property Value
Inherited
Determines if subcommands added to Commands should also have access to this option.
public bool Inherited { get; set; }
Property Value
LongName
The long command line flag used to identify this option. On command line, this is preceded by a double dash: '--{LongName}'.
public string? LongName { get; set; }
Property Value
OptionType
Defines the type of the option.
public CommandOptionType OptionType { get; }
Property Value
ShortName
The short command line flag used to identify this option. On command line, this is preceded by a single '-{ShortName}'.
public string? ShortName { get; set; }
Property Value
ShowInHelpText
Determines if this option should be shown in generated help text.
public bool ShowInHelpText { get; set; }
Property Value
SymbolName
Can be used in addition to ShortName to add a single, non-English character. Example "-?".
public string? SymbolName { get; set; }
Property Value
Validators
A collection of validators that execute before invoking OnExecute(Func<int>). When validation fails, ValidationErrorHandler is invoked.
public ICollection<IOptionValidator> Validators { get; }
Property Value
ValueName
The name of value(s) shown in help text when OptionType is not NoValue.
public string? ValueName { get; set; }
Property Value
Values
Any values found during parsing, if any.
public IReadOnlyList<string?> Values { get; }
Property Value
Methods
HasValue()
True when Values is not empty or when a DefaultValue is given.
public bool HasValue()
Returns
Reset()
Clear any parsed values from this argument.
public virtual void Reset()
TryParse(string?)
Attempt to parse the value that follows after the flag.
public bool TryParse(string? value)
Parameters
valuestring
Returns
Value()
Returns the first element of Values, if any, or DefaultValue.
public string? Value()