Table of Contents

Class CommandBuilder

Namespace
Albatross.CommandLine
Assembly
Albatross.CommandLine.dll

Builds and manages a hierarchical command structure for command-line interfaces. Commands are organized by space-separated keys (e.g., "parent child") that define the hierarchy.

public class CommandBuilder
Inheritance
CommandBuilder
Inherited Members

Constructors

CommandBuilder(string)

Creates a new command builder with the specified description for the root command. The root command includes a global verbosity option by default.

public CommandBuilder(string rootCommandDescription)

Parameters

rootCommandDescription string

The description to display in help text for the root command.

Properties

RootCommand

Gets the root command of the command hierarchy.

public RootCommand RootCommand { get; }

Property Value

RootCommand

VerbosityOption

Gets the global verbosity option shared across all commands.

public static VerbosityOption VerbosityOption { get; }

Property Value

VerbosityOption

Methods

Add<T>(string)

Adds a new command instance of the specified type to the command hierarchy.

public T Add<T>(string key) where T : Command, new()

Parameters

key string

The space-separated key defining the command's position in the hierarchy.

Returns

T

The newly created command instance.

Type Parameters

T

The command type to instantiate and add.

Add<T>(string, T)

Adds an existing command to the command hierarchy.

public void Add<T>(string key, T command) where T : Command

Parameters

key string

The space-separated key defining the command's position in the hierarchy.

command T

The command instance to add.

Type Parameters

T

The command type.

Exceptions

ArgumentException

Thrown when a command with the same key already exists.

BuildTree(Func<IServiceProvider>)

Builds the complete command tree by linking child commands to their parents and setting up command actions. This method should be called after all commands have been added and before parsing.

public void BuildTree(Func<IServiceProvider> serviceFactory)

Parameters

serviceFactory Func<IServiceProvider>

A factory function that provides the service provider for dependency injection.

ParseCommandText(string, out string, out string)

Parse the command text and return the immediate (last) sub command and its complete parent command if the text is "a b c", it will return "c" as self and "a b" as parent

public static void ParseCommandText(string commandText, out string parent, out string self)

Parameters

commandText string
parent string
self string