Search Results for

    Show / Hide Table of Contents

    Class CommandOption

    Represents one or many command line option that is identified by flag proceeded by '-' or '--'. Options are not positional. Compare to CommandArgument.

    Inheritance
    System.Object
    CommandOption
    CommandOption<T>
    Namespace: McMaster.Extensions.CommandLineUtils
    Assembly: McMaster.Extensions.CommandLineUtils.dll
    Syntax
    public class CommandOption

    Constructors

    | Improve this Doc View Source

    CommandOption(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 Source

    Description

    A description of this option to show in generated help text.

    Declaration
    public string Description { get; set; }
    Property Value
    Type Description
    System.String
    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    OptionType

    Defines the type of the option.

    Declaration
    public CommandOptionType OptionType { get; }
    Property Value
    Type Description
    CommandOptionType
    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    ShowInHelpText

    Determines if this option should be shown in generated help text.

    Declaration
    public bool ShowInHelpText { get; set; }
    Property Value
    Type Description
    System.Boolean
    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    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>
    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    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 Source

    HasValue()

    True when Values is not empty.

    Declaration
    public bool HasValue()
    Returns
    Type Description
    System.Boolean
    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    Value()

    Returns the first element of Values, if any.

    Declaration
    public string Value()
    Returns
    Type Description
    System.String

    Extension Methods

    ValidationExtensions.IsRequired(CommandOption, Boolean, String)
    ValidationExtensions.Accepts(CommandOption, Action<IOptionValidationBuilder>)
    ValidationExtensions.Accepts(CommandOption)
    ValidationExtensions.OnValidate(CommandOption, Func<ValidationContext, ValidationResult>)
    • Improve this Doc
    • View Source
    In This Article
    Back to top