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
commandHostCommandHostThe command host to add the command to.
parentKeystringThe space-separated key of the parent command, or null/empty for the root.
commandCommandThe 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
commandCommandThe 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
commandCommandThe 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
commandTCommandThe command containing the option.
funcFunc<TCommand, TOption>A function to select the option from the command.
hostCommandHostThe command host providing the service provider.
Returns
- TCommand
The command for method chaining.
Type Parameters
TCommandThe type of the command.
TOptionThe type of the option.
THandlerThe 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
commandTCommandThe command containing the option.
funcFunc<TCommand, TOption>A function to select the option from the command.
hostCommandHostThe command host providing the service provider.
Returns
- TCommand
The command for method chaining.
Type Parameters
TCommandThe type of the command.
TOptionThe type of the option.
THandlerThe type of the option handler.
TValueThe type of the value returned by the handler.