Table of Contents

Class Extensions

Namespace
Albatross.CommandLine
Assembly
Albatross.CommandLine.dll

Extension methods for command-line configuration and command hierarchy management.

public static class Extensions
Inheritance
Extensions
Inherited Members

Methods

AddCommand(CommandHost, string?, Command)

Adds a command to the command host under the specified parent.

public static CommandHost AddCommand(this CommandHost commandHost, string? parentKey, Command command)

Parameters

commandHost CommandHost

The command host to add the command to.

parentKey string

The space-separated key of the parent command, or null/empty for the root.

command Command

The command to add.

Returns

CommandHost

The command host for method chaining.

GetCommandKey(Command)

Gets the space-separated key that identifies this command in the hierarchy.

public static string GetCommandKey(this Command command)

Parameters

command Command

The command to get the key for.

Returns

string

A space-separated string of command names from root to this command.

GetCommandNames(Command)

Gets the names of all commands in the hierarchy from root to this command.

public static string[] GetCommandNames(this Command command)

Parameters

command Command

The command to get names for.

Returns

string[]

An array of command names from the root to this command, excluding the root command.

Exceptions

InvalidOperationException

Thrown when a circular reference is detected in the command hierarchy.

SetOptionAction<TCommand, TOption, THandler>(TCommand, Func<TCommand, TOption>, CommandHost)

Sets an async option handler for the specified option on a command.

public static TCommand SetOptionAction<TCommand, TOption, THandler>(this TCommand command, Func<TCommand, TOption> func, CommandHost host) where TCommand : Command where TOption : Option where THandler : IAsyncOptionHandler<TOption>

Parameters

command TCommand

The command containing the option.

func Func<TCommand, TOption>

A function to select the option from the command.

host CommandHost

The command host providing the service provider.

Returns

TCommand

The command for method chaining.

Type Parameters

TCommand

The type of the command.

TOption

The type of the option.

THandler

The type of the option handler.

SetOptionAction<TCommand, TOption, THandler, TValue>(TCommand, Func<TCommand, TOption>, CommandHost)

Sets an async option handler that returns a value for the specified option on a command. The returned value is stored in the command context for use by subsequent handlers.

public static TCommand SetOptionAction<TCommand, TOption, THandler, TValue>(this TCommand command, Func<TCommand, TOption> func, CommandHost host) where TCommand : Command where TOption : Option where THandler : IAsyncOptionHandler<TOption, TValue> where TValue : notnull

Parameters

command TCommand

The command containing the option.

func Func<TCommand, TOption>

A function to select the option from the command.

host CommandHost

The command host providing the service provider.

Returns

TCommand

The command for method chaining.

Type Parameters

TCommand

The type of the command.

TOption

The type of the option.

THandler

The type of the option handler.

TValue

The type of the value returned by the handler.