Class CommandLineApplicationExtensions
- Namespace
- McMaster.Extensions.CommandLineUtils
- Assembly
- McMaster.Extensions.CommandLineUtils.dll
Helper methods for CommandLineApplication.
public static class CommandLineApplicationExtensions
- Inheritance
-
objectCommandLineApplicationExtensions
Methods
Argument<T>(CommandLineApplication, string, string, bool)
Adds a command line argument with values that should be parsable into T.
public static CommandArgument<T> Argument<T>(this CommandLineApplication app, string name, string description, bool multipleValues = false)
Parameters
appCommandLineApplicationnamestringdescriptionstringmultipleValuesbool
Returns
Type Parameters
T
HelpOption(CommandLineApplication)
Adds the help option with the template -?|-h|--help.
public static CommandOption HelpOption(this CommandLineApplication app)
Parameters
Returns
HelpOption(CommandLineApplication, bool)
Adds the help option with the template -?|-h|--help.
public static CommandOption HelpOption(this CommandLineApplication app, bool inherited)
Parameters
appCommandLineApplicationinheritedbool
Returns
OnExecute(CommandLineApplication, Action)
Sets the command execution handler with a return code of 0.
public static void OnExecute(this CommandLineApplication app, Action action)
Parameters
appCommandLineApplicationactionActionAn action to invoke when the command is selected.
OnExecuteAsync(CommandLineApplication, Func<CancellationToken, Task>)
Sets an async command execution handler with a return code of 0.
public static void OnExecuteAsync(this CommandLineApplication app, Func<CancellationToken, Task> action)
Parameters
appCommandLineApplicationactionFunc<CancellationToken, Task>An asynchronous action to invoke when the command is selected..
OnValidationError(CommandLineApplication, Action<ValidationResult>)
Sets an action to invoke, but only when there is a validation error.
public static void OnValidationError(this CommandLineApplication app, Action<ValidationResult> action)
Parameters
appCommandLineApplicationactionAction<ValidationResult>
OnValidationError(CommandLineApplication, Func<ValidationResult, int>)
Sets an action to invoke, but only when there is a validation error.
public static void OnValidationError(this CommandLineApplication app, Func<ValidationResult, int> action)
Parameters
appCommandLineApplicationactionFunc<ValidationResult, int>
Option<T>(CommandLineApplication, string, string, CommandOptionType)
Adds a command-line option with values that should be parsable into T.
public static CommandOption<T> Option<T>(this CommandLineApplication app, string template, string description, CommandOptionType optionType)
Parameters
appCommandLineApplicationtemplatestringdescriptionstringoptionTypeCommandOptionType
Returns
Type Parameters
T
Option<T>(CommandLineApplication, string, string, CommandOptionType, Action<CommandOption<T>>)
Adds a command-line option with values that should be parsable into T.
public static CommandOption<T> Option<T>(this CommandLineApplication app, string template, string description, CommandOptionType optionType, Action<CommandOption<T>> configuration)
Parameters
appCommandLineApplicationtemplatestringdescriptionstringoptionTypeCommandOptionTypeconfigurationAction<CommandOption<T>>
Returns
Type Parameters
T
Option<T>(CommandLineApplication, string, string, CommandOptionType, bool)
Adds a command-line option with values that should be parsable into T.
public static CommandOption<T> Option<T>(this CommandLineApplication app, string template, string description, CommandOptionType optionType, bool inherited)
Parameters
appCommandLineApplicationtemplatestringdescriptionstringoptionTypeCommandOptionTypeinheritedbool
Returns
Type Parameters
T
VerboseOption(CommandLineApplication)
Adds the verbose option with the template -v|--verbose.
public static CommandOption VerboseOption(this CommandLineApplication app)
Parameters
Returns
VerboseOption(CommandLineApplication, string)
Adds the verbose option with the template -v|--verbose.
public static CommandOption VerboseOption(this CommandLineApplication app, string template)
Parameters
appCommandLineApplicationtemplatestring
Returns
VersionOptionFromAssemblyAttributes(CommandLineApplication, Assembly)
Finds AssemblyInformationalVersionAttribute on assembly and uses that
to set OptionVersion.
Uses the Version that is part of the AssemblyName of the specified assembly if no AssemblyInformationalVersionAttribute is applied.
public static CommandOption VersionOptionFromAssemblyAttributes(this CommandLineApplication app, Assembly assembly)
Parameters
appCommandLineApplicationassemblyAssembly
Returns
Exceptions
- ArgumentNullException
Either
apporassemblyisnull.
VersionOptionFromAssemblyAttributes(CommandLineApplication, string, Assembly)
Finds AssemblyInformationalVersionAttribute on assembly and uses that
to set OptionVersion.
Uses the Version that is part of the AssemblyName of the specified assembly if no AssemblyInformationalVersionAttribute is applied.
public static CommandOption VersionOptionFromAssemblyAttributes(this CommandLineApplication app, string template, Assembly assembly)
Parameters
appCommandLineApplicationtemplatestringassemblyAssembly
Returns
Exceptions
- ArgumentNullException
Either
apporassemblyisnull.