Search Results for

    Show / Hide Table of Contents

    Class CommandLineApplication

    Describes a set of command line arguments, options, and execution behavior. CommandLineApplication can be nested to support subcommands.

    Inheritance
    System.Object
    CommandLineApplication
    CommandLineApplication<TModel>
    Implements
    System.IServiceProvider
    System.IDisposable
    Namespace: McMaster.Extensions.CommandLineUtils
    Assembly: McMaster.Extensions.CommandLineUtils.dll
    Syntax
    public class CommandLineApplication : IServiceProvider, IDisposable

    Constructors

    | Improve this Doc View Source

    CommandLineApplication()

    Initializes a new instance of CommandLineApplication.

    Declaration
    public CommandLineApplication()
    | Improve this Doc View Source

    CommandLineApplication(IHelpTextGenerator, IConsole, String)

    Initializes a new instance of CommandLineApplication.

    Declaration
    public CommandLineApplication(IHelpTextGenerator helpTextGenerator, IConsole console, string workingDirectory)
    Parameters
    Type Name Description
    IHelpTextGenerator helpTextGenerator

    The help text generator to use.

    IConsole console

    The console implementation to use.

    System.String workingDirectory

    The current working directory.

    | Improve this Doc View Source

    CommandLineApplication(IConsole)

    Initializes a new instance of CommandLineApplication.

    Declaration
    public CommandLineApplication(IConsole console)
    Parameters
    Type Name Description
    IConsole console

    The console implementation to use.

    | Improve this Doc View Source

    CommandLineApplication(IConsole, String)

    Initializes a new instance of CommandLineApplication.

    Declaration
    public CommandLineApplication(IConsole console, string workingDirectory)
    Parameters
    Type Name Description
    IConsole console

    The console implementation to use.

    System.String workingDirectory

    The current working directory.

    Properties

    | Improve this Doc View Source

    AllowArgumentSeparator

    Determines if '--' can be used to separate known arguments and options from additional content passed to RemainingArguments.

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

    Arguments

    Required command-line arguments.

    Declaration
    public List<CommandArgument> Arguments { get; }
    Property Value
    Type Description
    System.Collections.Generic.List<CommandArgument>
    | Improve this Doc View Source

    ClusterOptions

    One or more options of NoValue, followed by at most one option that takes values, should be accepted when grouped behind one '-' delimiter.

    When true, the following are equivalent.

    -abcXyellow
    -abcX=yellow
    -abcX:yellow
    -abc -X=yellow
    -ab -cX=yellow
    -a -b -c -Xyellow
    -a -b -c -X yellow
    -a -b -c -X=yellow
    -a -b -c -X:yellow

    This defaults to true unless an option with a short name of two or more characters is added.

    Declaration
    public bool ClusterOptions { get; set; }
    Property Value
    Type Description
    System.Boolean
    Remarks

    https://www.gnu.org/software/libc/manual/html_node/Argument-Syntax.html

    | Improve this Doc View Source

    Commands

    Subcommands.

    Declaration
    public List<CommandLineApplication> Commands { get; }
    Property Value
    Type Description
    System.Collections.Generic.List<CommandLineApplication>
    | Improve this Doc View Source

    Conventions

    Gets a builder that can be used to apply conventions to

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

    Description

    A description of the command.

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

    Error

    The writer used to display generated error messages.

    Declaration
    public TextWriter Error { get; set; }
    Property Value
    Type Description
    System.IO.TextWriter
    | Improve this Doc View Source

    ExtendedHelpText

    Additional text that appears at the bottom of generated help text.

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

    FullName

    The full name of the command to show in the help text.

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

    HelpTextGenerator

    The help text generator to use.

    Declaration
    public IHelpTextGenerator HelpTextGenerator { get; set; }
    Property Value
    Type Description
    IHelpTextGenerator
    | Improve this Doc View Source

    IsShowingInformation

    True when OptionHelp or OptionVersion was matched.

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

    LongVersionGetter

    The long-form of the version to display in generated help text.

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

    MakeSuggestionsInErrorMessage

    When an invalid argument is given, make suggestions in the error message about similar, valid commands or options.

    $ git pshu Specify --help for a list of available options and commands Unrecognized command or argument 'pshu'

    Did you mean this? push

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

    Name

    The short name of the command. When this is a subcommand, it is the name of the word used to invoke the subcommand.

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

    Names

    All names by which the command can be referenced. This includes Name and an aliases added in AddName(String).

    Declaration
    public IEnumerable<string> Names { get; }
    Property Value
    Type Description
    System.Collections.Generic.IEnumerable<System.String>
    | Improve this Doc View Source

    OptionHelp

    The option used to determine if help text should be displayed. This is set by calling HelpOption(String).

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

    OptionNameValueSeparators

    Characters used to separate the option name from the value.

    By default, allowed separators are ' ' (space), :, and =

    Declaration
    public char[] OptionNameValueSeparators { get; set; }
    Property Value
    Type Description
    System.Char[]
    Remarks

    Space actually implies multiple spaces due to the way most operating system shells parse command line arguments before starting a new process.

    Examples

    Given --name=value, = is the separator.

    | Improve this Doc View Source

    Options

    Available command-line options on this command. Use GetOptions() to get all available options, which may include inherited options.

    Declaration
    public List<CommandOption> Options { get; }
    Property Value
    Type Description
    System.Collections.Generic.List<CommandOption>
    | Improve this Doc View Source

    OptionsComparison

    The way arguments and options are matched.

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

    OptionVersion

    The options used to determine if the command version should be displayed. This is set by calling VersionOption(String, Func<String>, Func<String>).

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

    Out

    The writer used to display generated help text.

    Declaration
    public TextWriter Out { get; set; }
    Property Value
    Type Description
    System.IO.TextWriter
    | Improve this Doc View Source

    Parent

    Defaults to null. A link to the parent command if this is instance is a subcommand.

    Declaration
    public CommandLineApplication Parent { get; set; }
    Property Value
    Type Description
    CommandLineApplication
    | Improve this Doc View Source

    RemainingArguments

    When initialized when UnrecognizedArgumentHandling is StopParsingAndCollect, this will contain any unrecognized arguments.

    Declaration
    public List<string> RemainingArguments { get; }
    Property Value
    Type Description
    System.Collections.Generic.List<System.String>
    | Improve this Doc View Source

    ResponseFileHandling

    When enabled, the parser will treat any arguments beginning with &apos;@' as a file path to a response file. A response file contains additional arguments that will be treated as if they were passed in on the command line.

    Defaults to Disabled.

    Nested response false are not supported.

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

    ShortVersionGetter

    The short-form of the version to display in generated help text.

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

    ShowInHelpText

    Determines if this command appears in generated help text.

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

    UnrecognizedArgumentHandling

    Configures what the parser should do when it runs into an unexpected argument.

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

    UsePagerForHelpText

    Whether a Pager should be used to display help text.

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

    ValidationErrorHandler

    The action to call when the command executes, but there was an error validation options or arguments. The action can return a new validation result.

    Declaration
    public Func<ValidationResult, int> ValidationErrorHandler { get; set; }
    Property Value
    Type Description
    System.Func<System.ComponentModel.DataAnnotations.ValidationResult, System.Int32>
    | 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<ICommandValidator> Validators { get; }
    Property Value
    Type Description
    System.Collections.Generic.ICollection<ICommandValidator>
    | Improve this Doc View Source

    ValueParsers

    Gets the default value parser provider.

    The value parsers control how argument values are converted from strings to other types. Additional value parsers can be added so that domain specific types can converted. In-built value parsers can also be replaced for precise control of all type conversion.

    Value parsers are currently only used by the Attribute API.

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

    WorkingDirectory

    Defines the working directory of the application. Defaults to System.IO.Directory.GetCurrentDirectory.

    This will be used as the base path for opening response files when ResponseFileHandling is true.

    Declaration
    public string WorkingDirectory { get; }
    Property Value
    Type Description
    System.String

    Methods

    | Improve this Doc View Source

    AddName(String)

    Add another name for the command.

    Additional names can be shorter, longer, or alternative names by which a command may be invoked on the command line.

    Declaration
    public void AddName(string name)
    Parameters
    Type Name Description
    System.String name

    The name. Must not be null or empty.

    | Improve this Doc View Source

    AddSubcommand(CommandLineApplication)

    Add a subcommand

    Declaration
    public void AddSubcommand(CommandLineApplication subcommand)
    Parameters
    Type Name Description
    CommandLineApplication subcommand
    | Improve this Doc View Source

    Argument(String, String, Action<CommandArgument>, Boolean)

    Adds a command line argument.

    Declaration
    public CommandArgument Argument(string name, string description, Action<CommandArgument> configuration, bool multipleValues = false)
    Parameters
    Type Name Description
    System.String name
    System.String description
    System.Action<CommandArgument> configuration
    System.Boolean multipleValues
    Returns
    Type Description
    CommandArgument
    | Improve this Doc View Source

    Argument(String, String, Boolean)

    Adds a command line argument

    Declaration
    public CommandArgument Argument(string name, string description, bool multipleValues = false)
    Parameters
    Type Name Description
    System.String name
    System.String description
    System.Boolean multipleValues
    Returns
    Type Description
    CommandArgument
    | Improve this Doc View Source

    Argument<T>(String, String, Action<CommandArgument>, Boolean)

    Adds a command line argument with values that should be parsable into T.

    Declaration
    public CommandArgument<T> Argument<T>(string name, string description, Action<CommandArgument> configuration, bool multipleValues = false)
    Parameters
    Type Name Description
    System.String name
    System.String description
    System.Action<CommandArgument> configuration
    System.Boolean multipleValues
    Returns
    Type Description
    CommandArgument<T>
    Type Parameters
    Name Description
    T

    The type of the values on the option

    | Improve this Doc View Source

    Command(String, Action<CommandLineApplication>)

    Adds a subcommand.

    Declaration
    public CommandLineApplication Command(string name, Action<CommandLineApplication> configuration)
    Parameters
    Type Name Description
    System.String name

    The word used to invoke the subcommand.

    System.Action<CommandLineApplication> configuration

    A callback to configure the created subcommand.

    Returns
    Type Description
    CommandLineApplication
    | Improve this Doc View Source

    Command<TModel>(String, Action<CommandLineApplication<TModel>>)

    Adds a subcommand with model of type TModel.

    Declaration
    public CommandLineApplication<TModel> Command<TModel>(string name, Action<CommandLineApplication<TModel>> configuration)
        where TModel : class
    Parameters
    Type Name Description
    System.String name

    The word used to invoke the subcommand.

    System.Action<CommandLineApplication<TModel>> configuration

    A callback used to configure the subcommand object.

    Returns
    Type Description
    CommandLineApplication<TModel>
    Type Parameters
    Name Description
    TModel

    The model type of the subcommand.

    | Improve this Doc View Source

    Dispose()

    Declaration
    public virtual void Dispose()
    | Improve this Doc View Source

    Execute(String[])

    Parses an array of strings using Parse(String[]).

    If OptionHelp was matched, the generated help text is displayed in command line output.

    If OptionVersion was matched, the generated version info is displayed in command line output.

    If there were any validation errors produced from GetValidationResult(), ValidationErrorHandler is invoked.

    If the parse result matches this command, the function passed to OnExecute(Func<Int32>) or OnExecuteAsync(Func<CancellationToken, Task<Int32>>) will be invoked.

    Declaration
    public int Execute(params string[] args)
    Parameters
    Type Name Description
    System.String[] args
    Returns
    Type Description
    System.Int32

    The return code from the function passed to OnExecute(Func<Int32>) or OnExecuteAsync(Func<CancellationToken, Task<Int32>>).

    | Improve this Doc View Source

    Execute<TApp>(CommandLineContext)

    Creates an instance of TApp, matching Arguments to all attributes on the type, and then invoking a method named "OnExecute" or "OnExecuteAsync" if it exists.

    Declaration
    public static int Execute<TApp>(CommandLineContext context)
        where TApp : class
    Parameters
    Type Name Description
    CommandLineContext context

    The execution context.

    Returns
    Type Description
    System.Int32

    The process exit code

    Type Parameters
    Name Description
    TApp

    A type that should be bound to the arguments.

    Exceptions
    Type Condition
    System.InvalidOperationException

    Thrown when attributes are incorrectly configured.

    See Also
    OptionAttribute
    ArgumentAttribute
    HelpOptionAttribute
    VersionOptionAttribute
    | Improve this Doc View Source

    Execute<TApp>(IConsole, String[])

    Creates an instance of TApp, matching args to all attributes on the type, and then invoking a method named "OnExecute" or "OnExecuteAsync" if it exists.

    Declaration
    public static int Execute<TApp>(IConsole console, params string[] args)
        where TApp : class
    Parameters
    Type Name Description
    IConsole console

    The console to use

    System.String[] args

    The arguments

    Returns
    Type Description
    System.Int32

    The process exit code

    Type Parameters
    Name Description
    TApp

    A type that should be bound to the arguments.

    Exceptions
    Type Condition
    System.InvalidOperationException

    Thrown when attributes are incorrectly configured.

    See Also
    OptionAttribute
    ArgumentAttribute
    HelpOptionAttribute
    VersionOptionAttribute
    | Improve this Doc View Source

    Execute<TApp>(String[])

    Creates an instance of TApp, matching args to all attributes on the type, and then invoking a method named "OnExecute" or "OnExecuteAsync" if it exists.

    Declaration
    public static int Execute<TApp>(params string[] args)
        where TApp : class
    Parameters
    Type Name Description
    System.String[] args

    The arguments

    Returns
    Type Description
    System.Int32

    The process exit code

    Type Parameters
    Name Description
    TApp

    A type that should be bound to the arguments.

    Exceptions
    Type Condition
    System.InvalidOperationException

    Thrown when attributes are incorrectly configured.

    See Also
    OptionAttribute
    ArgumentAttribute
    HelpOptionAttribute
    VersionOptionAttribute
    | Improve this Doc View Source

    ExecuteAsync(String[], CancellationToken)

    Parses an array of strings using Parse(String[]).

    If OptionHelp was matched, the generated help text is displayed in command line output.

    If OptionVersion was matched, the generated version info is displayed in command line output.

    If there were any validation errors produced from GetValidationResult(), ValidationErrorHandler is invoked.

    If the parse result matches this command, the function passed to OnExecute(Func<Int32>) or OnExecuteAsync(Func<CancellationToken, Task<Int32>>) will be invoked.

    Declaration
    public Task<int> ExecuteAsync(string[] args, CancellationToken cancellationToken = default(CancellationToken))
    Parameters
    Type Name Description
    System.String[] args
    System.Threading.CancellationToken cancellationToken
    Returns
    Type Description
    System.Threading.Tasks.Task<System.Int32>

    The return code from the function passed to OnExecute(Func<Int32>) or OnExecuteAsync(Func<CancellationToken, Task<Int32>>).

    | Improve this Doc View Source

    ExecuteAsync<TApp>(CommandLineContext, CancellationToken)

    Creates an instance of TApp, matching Arguments to all attributes on the type, and then invoking a method named "OnExecute" or "OnExecuteAsync" if it exists.

    Declaration
    public static Task<int> ExecuteAsync<TApp>(CommandLineContext context, CancellationToken cancellationToken = default(CancellationToken))
        where TApp : class
    Parameters
    Type Name Description
    CommandLineContext context

    The execution context.

    System.Threading.CancellationToken cancellationToken
    Returns
    Type Description
    System.Threading.Tasks.Task<System.Int32>

    The process exit code

    Type Parameters
    Name Description
    TApp

    A type that should be bound to the arguments.

    Exceptions
    Type Condition
    System.InvalidOperationException

    Thrown when attributes are incorrectly configured.

    See Also
    OptionAttribute
    ArgumentAttribute
    HelpOptionAttribute
    VersionOptionAttribute
    | Improve this Doc View Source

    ExecuteAsync<TApp>(IConsole, String[])

    Creates an instance of TApp, matching args to all attributes on the type, and then invoking a method named "OnExecute" or "OnExecuteAsync" if it exists.

    Declaration
    public static Task<int> ExecuteAsync<TApp>(IConsole console, params string[] args)
        where TApp : class
    Parameters
    Type Name Description
    IConsole console

    The console to use

    System.String[] args

    The arguments

    Returns
    Type Description
    System.Threading.Tasks.Task<System.Int32>

    The process exit code

    Type Parameters
    Name Description
    TApp

    A type that should be bound to the arguments.

    Exceptions
    Type Condition
    System.InvalidOperationException

    Thrown when attributes are incorrectly configured.

    See Also
    OptionAttribute
    ArgumentAttribute
    HelpOptionAttribute
    VersionOptionAttribute
    | Improve this Doc View Source

    ExecuteAsync<TApp>(String[])

    Creates an instance of TApp, matching args to all attributes on the type, and then invoking a method named "OnExecute" or "OnExecuteAsync" if it exists.

    Declaration
    public static Task<int> ExecuteAsync<TApp>(params string[] args)
        where TApp : class
    Parameters
    Type Name Description
    System.String[] args

    The arguments

    Returns
    Type Description
    System.Threading.Tasks.Task<System.Int32>

    The process exit code

    Type Parameters
    Name Description
    TApp

    A type that should be bound to the arguments.

    Exceptions
    Type Condition
    System.InvalidOperationException

    Thrown when attributes are incorrectly configured.

    See Also
    OptionAttribute
    ArgumentAttribute
    HelpOptionAttribute
    VersionOptionAttribute
    | Improve this Doc View Source

    ExecuteAsync<TApp>(String[], CancellationToken)

    Creates an instance of TApp, matching args to all attributes on the type, and then invoking a method named "OnExecute" or "OnExecuteAsync" if it exists.

    Declaration
    public static Task<int> ExecuteAsync<TApp>(string[] args, CancellationToken cancellationToken = default(CancellationToken))
        where TApp : class
    Parameters
    Type Name Description
    System.String[] args

    The arguments

    System.Threading.CancellationToken cancellationToken
    Returns
    Type Description
    System.Threading.Tasks.Task<System.Int32>

    The process exit code

    Type Parameters
    Name Description
    TApp

    A type that should be bound to the arguments.

    Exceptions
    Type Condition
    System.InvalidOperationException

    Thrown when attributes are incorrectly configured.

    See Also
    OptionAttribute
    ArgumentAttribute
    HelpOptionAttribute
    VersionOptionAttribute
    | Improve this Doc View Source

    GetFullNameAndVersion()

    Gets FullName and ShortVersionGetter.

    Declaration
    public virtual string GetFullNameAndVersion()
    Returns
    Type Description
    System.String
    | Improve this Doc View Source

    GetHelpText()

    Produces help text describing command usage.

    Declaration
    public virtual string GetHelpText()
    Returns
    Type Description
    System.String

    The help text.

    | Improve this Doc View Source

    GetOptions()

    Gets all command line options available to this command, including any inherited options.

    Declaration
    public IEnumerable<CommandOption> GetOptions()
    Returns
    Type Description
    System.Collections.Generic.IEnumerable<CommandOption>

    Command line options.

    | Improve this Doc View Source

    GetValidationResult()

    Validates arguments and options.

    Declaration
    public ValidationResult GetValidationResult()
    Returns
    Type Description
    System.ComponentModel.DataAnnotations.ValidationResult

    The first validation result that is not System.ComponentModel.DataAnnotations.ValidationResult.Success if there is an error.

    | Improve this Doc View Source

    GetVersionText()

    Produces text describing version of the command.

    Declaration
    public virtual string GetVersionText()
    Returns
    Type Description
    System.String

    The version text.

    | Improve this Doc View Source

    HandleParseResult(ParseResult)

    Handle the result of parsing command line arguments.

    Declaration
    protected virtual void HandleParseResult(ParseResult parseResult)
    Parameters
    Type Name Description
    ParseResult parseResult

    The parse result.

    | Improve this Doc View Source

    HelpOption(String)

    Helper method that adds a help option.

    Declaration
    public CommandOption HelpOption(string template)
    Parameters
    Type Name Description
    System.String template
    Returns
    Type Description
    CommandOption
    | Improve this Doc View Source

    HelpOption(String, Boolean)

    Helper method that adds a help option.

    Declaration
    public CommandOption HelpOption(string template, bool inherited)
    Parameters
    Type Name Description
    System.String template
    System.Boolean inherited
    Returns
    Type Description
    CommandOption
    | Improve this Doc View Source

    OnExecute(Func<Int32>)

    Defines a callback for when this command is invoked.

    Declaration
    public void OnExecute(Func<int> invoke)
    Parameters
    Type Name Description
    System.Func<System.Int32> invoke
    | Improve this Doc View Source

    OnExecuteAsync(Func<CancellationToken, Task<Int32>>)

    Defines an asynchronous callback.

    Declaration
    public void OnExecuteAsync(Func<CancellationToken, Task<int>> invoke)
    Parameters
    Type Name Description
    System.Func<System.Threading.CancellationToken, System.Threading.Tasks.Task<System.Int32>> invoke
    | Improve this Doc View Source

    OnParsingComplete(Action<ParseResult>)

    Adds an action to be invoked when all command line arguments have been parsed and validated.

    Declaration
    public void OnParsingComplete(Action<ParseResult> action)
    Parameters
    Type Name Description
    System.Action<ParseResult> action

    The action to be invoked

    | Improve this Doc View Source

    Option(String, String, CommandOptionType)

    Adds a command-line option.

    Declaration
    public CommandOption Option(string template, string description, CommandOptionType optionType)
    Parameters
    Type Name Description
    System.String template
    System.String description
    CommandOptionType optionType
    Returns
    Type Description
    CommandOption
    | Improve this Doc View Source

    Option(String, String, CommandOptionType, Action<CommandOption>)

    Adds a command-line option.

    Declaration
    public CommandOption Option(string template, string description, CommandOptionType optionType, Action<CommandOption> configuration)
    Parameters
    Type Name Description
    System.String template
    System.String description
    CommandOptionType optionType
    System.Action<CommandOption> configuration
    Returns
    Type Description
    CommandOption
    | Improve this Doc View Source

    Option(String, String, CommandOptionType, Action<CommandOption>, Boolean)

    Adds a command line option.

    Declaration
    public CommandOption Option(string template, string description, CommandOptionType optionType, Action<CommandOption> configuration, bool inherited)
    Parameters
    Type Name Description
    System.String template
    System.String description
    CommandOptionType optionType
    System.Action<CommandOption> configuration
    System.Boolean inherited
    Returns
    Type Description
    CommandOption
    | Improve this Doc View Source

    Option(String, String, CommandOptionType, Boolean)

    Adds a command-line option.

    Declaration
    public CommandOption Option(string template, string description, CommandOptionType optionType, bool inherited)
    Parameters
    Type Name Description
    System.String template
    System.String description
    CommandOptionType optionType
    System.Boolean inherited
    Returns
    Type Description
    CommandOption
    | Improve this Doc View Source

    Option<T>(String, String, CommandOptionType, Action<CommandOption>, Boolean)

    Adds a command line option with values that should be parsable into T.

    Declaration
    public CommandOption<T> Option<T>(string template, string description, CommandOptionType optionType, Action<CommandOption> configuration, bool inherited)
    Parameters
    Type Name Description
    System.String template
    System.String description
    CommandOptionType optionType
    System.Action<CommandOption> configuration
    System.Boolean inherited
    Returns
    Type Description
    CommandOption<T>

    The option

    Type Parameters
    Name Description
    T

    The type of the values on the option

    | Improve this Doc View Source

    Parse(String[])

    Parses an array of strings, matching them against Options, Arguments, and Commands.

    Declaration
    public ParseResult Parse(params string[] args)
    Parameters
    Type Name Description
    System.String[] args

    Command line arguments.

    Returns
    Type Description
    ParseResult

    The result of parsing.

    | Improve this Doc View Source

    ShowHelp()

    Show full help.

    Declaration
    public void ShowHelp()
    | Improve this Doc View Source

    ShowHelp(Boolean)

    Show full help.

    Declaration
    public void ShowHelp(bool usePager)
    Parameters
    Type Name Description
    System.Boolean usePager

    Use a console pager to display help text, if possible.

    | Improve this Doc View Source

    ShowHint()

    Show short hint that reminds users to use help option.

    Declaration
    public virtual void ShowHint()
    | Improve this Doc View Source

    ShowRootCommandFullNameAndVersion()

    Traverses up Parent and displays the result of GetFullNameAndVersion().

    Declaration
    public void ShowRootCommandFullNameAndVersion()
    | Improve this Doc View Source

    ShowVersion()

    Displays version information that includes FullName and LongVersionGetter.

    Declaration
    public void ShowVersion()
    | Improve this Doc View Source

    VersionOption(String, Func<String>, Func<String>)

    Helper method that adds a version option.

    Declaration
    public CommandOption VersionOption(string template, Func<string> shortFormVersionGetter, Func<string> longFormVersionGetter = null)
    Parameters
    Type Name Description
    System.String template
    System.Func<System.String> shortFormVersionGetter
    System.Func<System.String> longFormVersionGetter
    Returns
    Type Description
    CommandOption
    | Improve this Doc View Source

    VersionOption(String, String, String)

    Helper method that adds a version option from known versions strings.

    Declaration
    public CommandOption VersionOption(string template, string shortFormVersion, string longFormVersion = null)
    Parameters
    Type Name Description
    System.String template
    System.String shortFormVersion
    System.String longFormVersion
    Returns
    Type Description
    CommandOption

    Explicit Interface Implementations

    | Improve this Doc View Source

    IServiceProvider.GetService(Type)

    Declaration
    object IServiceProvider.GetService(Type serviceType)
    Parameters
    Type Name Description
    System.Type serviceType
    Returns
    Type Description
    System.Object

    Implements

    System.IServiceProvider
    System.IDisposable

    Extension Methods

    CommandLineApplicationExtensions.Argument<T>(CommandLineApplication, String, String, Boolean)
    CommandLineApplicationExtensions.Option<T>(CommandLineApplication, String, String, CommandOptionType)
    CommandLineApplicationExtensions.Option<T>(CommandLineApplication, String, String, CommandOptionType, Boolean)
    CommandLineApplicationExtensions.Option<T>(CommandLineApplication, String, String, CommandOptionType, Action<CommandOption>)
    CommandLineApplicationExtensions.HelpOption(CommandLineApplication)
    CommandLineApplicationExtensions.HelpOption(CommandLineApplication, Boolean)
    CommandLineApplicationExtensions.VerboseOption(CommandLineApplication)
    CommandLineApplicationExtensions.VerboseOption(CommandLineApplication, String)
    CommandLineApplicationExtensions.OnExecuteAsync(CommandLineApplication, Func<CancellationToken, Task>)
    CommandLineApplicationExtensions.OnExecute(CommandLineApplication, Action)
    CommandLineApplicationExtensions.OnValidationError(CommandLineApplication, Func<ValidationResult, Int32>)
    CommandLineApplicationExtensions.OnValidationError(CommandLineApplication, Action<ValidationResult>)
    CommandLineApplicationExtensions.VersionOptionFromAssemblyAttributes(CommandLineApplication, Assembly)
    CommandLineApplicationExtensions.VersionOptionFromAssemblyAttributes(CommandLineApplication, String, Assembly)
    ValidationExtensions.OnValidate(CommandLineApplication, Func<ValidationContext, ValidationResult>)
    • Improve this Doc
    • View Source
    In This Article
    Back to top