Table of Contents

Class CommandLineApplicationExtensions

Namespace
McMaster.Extensions.CommandLineUtils
Assembly
McMaster.Extensions.CommandLineUtils.dll

Helper methods for CommandLineApplication.

public static class CommandLineApplicationExtensions
Inheritance
object
CommandLineApplicationExtensions

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

app CommandLineApplication
name string
description string
multipleValues bool

Returns

CommandArgument<T>

Type Parameters

T

HelpOption(CommandLineApplication)

Adds the help option with the template -?|-h|--help.

public static CommandOption HelpOption(this CommandLineApplication app)

Parameters

app CommandLineApplication

Returns

CommandOption

HelpOption(CommandLineApplication, bool)

Adds the help option with the template -?|-h|--help.

public static CommandOption HelpOption(this CommandLineApplication app, bool inherited)

Parameters

app CommandLineApplication
inherited bool

Returns

CommandOption

OnExecute(CommandLineApplication, Action)

Sets the command execution handler with a return code of 0.

public static void OnExecute(this CommandLineApplication app, Action action)

Parameters

app CommandLineApplication
action Action

An 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

app CommandLineApplication
action Func<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

app CommandLineApplication
action Action<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

app CommandLineApplication
action Func<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

app CommandLineApplication
template string
description string
optionType CommandOptionType

Returns

CommandOption<T>

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

app CommandLineApplication
template string
description string
optionType CommandOptionType
configuration Action<CommandOption<T>>

Returns

CommandOption<T>

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

app CommandLineApplication
template string
description string
optionType CommandOptionType
inherited bool

Returns

CommandOption<T>

Type Parameters

T

VerboseOption(CommandLineApplication)

Adds the verbose option with the template -v|--verbose.

public static CommandOption VerboseOption(this CommandLineApplication app)

Parameters

app CommandLineApplication

Returns

CommandOption

VerboseOption(CommandLineApplication, string)

Adds the verbose option with the template -v|--verbose.

public static CommandOption VerboseOption(this CommandLineApplication app, string template)

Parameters

app CommandLineApplication
template string

Returns

CommandOption

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

app CommandLineApplication
assembly Assembly

Returns

CommandOption

Exceptions

ArgumentNullException

Either app or assembly is null.

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

app CommandLineApplication
template string
assembly Assembly

Returns

CommandOption

Exceptions

ArgumentNullException

Either app or assembly is null.