Table of Contents

Interface ICommandContext

Namespace
Albatross.CommandLine
Assembly
Albatross.CommandLine.dll

This interface is a command context with scoped lifetime. The same instance of the context can be injected to PreAction handlers as well as the Command handler. It can be used to share state between those handlers.

public interface ICommandContext

Properties

HasInputActionError

Gets a value indicating whether any option handler reported an error.

bool HasInputActionError { get; }

Property Value

bool

HasParsingError

Gets a value indicating whether the parse result contains errors.

bool HasParsingError { get; }

Property Value

bool

HasShortCircuitOptions

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

bool HasShortCircuitOptions { get; }

Property Value

bool

Key

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

string Key { get; }

Property Value

string

Result

Gets the parse result from command line parsing.

ParseResult Result { get; }

Property Value

ParseResult

Methods

GetRequiredValue<T>(string)

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

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.

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.

SetInputActionStatus(OptionHandlerStatus)

Records the status of an option handler execution.

void SetInputActionStatus(OptionHandlerStatus status)

Parameters

status OptionHandlerStatus

The status to record.

SetValue<T>(string, T)

Stores a value in the context for sharing between handlers.

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.