Table of Contents

Class CommandContext

Namespace
Albatross.CommandLine
Assembly
Albatross.CommandLine.dll

Default implementation of ICommandContext that provides state sharing between option handlers and command handlers.

public class CommandContext : ICommandContext, IAsyncDisposable
Inheritance
CommandContext
Implements
Inherited Members

Constructors

CommandContext(ParseResult)

Initializes a new command context from the parse result.

public CommandContext(ParseResult result)

Parameters

result ParseResult

Properties

HasParsingError

Gets a value indicating whether the parse result contains errors.

public bool HasParsingError { get; }

Property Value

bool

HasShortCircuitOptions

Gets a value indicating whether short-circuit options (like --help or --version) were specified.

public bool HasShortCircuitOptions { get; }

Property Value

bool

InputActionErrors

Gets the errors recorded by option handlers during the pre-action phase.

public IEnumerable<Error> InputActionErrors { get; }

Property Value

IEnumerable<Error>

Key

Gets the space-separated key identifying the current command in the hierarchy.

public string Key { get; }

Property Value

string

Result

Gets the parse result from command line parsing.

public ParseResult Result { get; }

Property Value

ParseResult

Methods

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

GetRequiredValue<T>(string)

Gets a required value from the context. Throws if the value is not found or has the wrong type.

public T GetRequiredValue<T>(string key)

Parameters

key string

The key identifying the value.

Returns

T

The stored value.

Type Parameters

T

The expected type of the value.

GetValue<T>(string)

Gets a value from the context, or default if not found.

public T? GetValue<T>(string key)

Parameters

key string

The key identifying the value.

Returns

T

The stored value, or default if not found.

Type Parameters

T

The expected type of the value.

SetInputActionError(Error)

Records an error produced by an option handler, keyed by the option name so the latest error for a given option replaces any earlier one.

public void SetInputActionError(Error error)

Parameters

error Error

The error to record.

SetValue<T>(string, T)

Stores a value in the context for sharing between handlers.

public void SetValue<T>(string key, T value) where T : notnull

Parameters

key string

The key to identify the value.

value T

The value to store.

Type Parameters

T

The type of the value.