Class CommandOption
Represents one or many command line option that is identified by flag proceeded by '-' or '--'. Options are not positional. Compare to CommandArgument.
Namespace: McMaster.Extensions.CommandLineUtils
Assembly: McMaster.Extensions.CommandLineUtils.dll
Syntax
public class CommandOption
Constructors
| Improve this Doc View SourceCommandOption(String, CommandOptionType)
Initializes a new CommandOption.
Declaration
public CommandOption(string template, CommandOptionType optionType)
Parameters
Type | Name | Description |
---|---|---|
System.String | template | The template string. This is parsed into ShortName and LongName. |
CommandOptionType | optionType | The option type. |
Properties
| Improve this Doc View SourceDescription
A description of this option to show in generated help text.
Declaration
public string Description { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Inherited
Determines if subcommands added to Commands should also have access to this option.
Declaration
public bool Inherited { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
LongName
The long command line flag used to identify this option. On command line, this is preceeded by a double dash: '--{LongName}'.
Declaration
public string LongName { get; set; }
Property Value
Type | Description |
---|---|
System.String |
OptionType
Defines the type of the option.
Declaration
public CommandOptionType OptionType { get; }
Property Value
Type | Description |
---|---|
CommandOptionType |
ShortName
The short command line flag used to identify this option. On command line, this is preceeded by a single '-{ShortName}'.
Declaration
public string ShortName { get; set; }
Property Value
Type | Description |
---|---|
System.String |
ShowInHelpText
Determines if this option should be shown in generated help text.
Declaration
public bool ShowInHelpText { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
SymbolName
Can be used in addition to ShortName to add a single, non-English character. Example "-?".
Declaration
public string SymbolName { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Validators
A collection of validators that execute before invoking OnExecute(Func<Int32>). When validation fails, ValidationErrorHandler is invoked.
Declaration
public ICollection<IOptionValidator> Validators { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.ICollection<IOptionValidator> |
ValueName
The name of value(s) shown in help text when OptionType is not NoValue.
Declaration
public string ValueName { get; set; }
Property Value
Type | Description |
---|---|
System.String |
Values
Any values found during parsing, if any.
Declaration
public List<string> Values { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.List<System.String> |
Methods
| Improve this Doc View SourceHasValue()
True when Values is not empty.
Declaration
public bool HasValue()
Returns
Type | Description |
---|---|
System.Boolean |
TryParse(String)
Attempt to parse the value that follows after the flag.
Declaration
public bool TryParse(string value)
Parameters
Type | Name | Description |
---|---|---|
System.String | value |
Returns
Type | Description |
---|---|
System.Boolean |
Value()
Returns the first element of Values, if any.
Declaration
public string Value()
Returns
Type | Description |
---|---|
System.String |