RazorDocs Search
API Reference

Console

Type

ConsoleOptions

Source

Represents configurable startup options for AppSurface console applications.

Property

Default

ConsoleOptions Default { get; } Source

Gets a default instance of ConsoleOptions.

Property

OutputMode

ConsoleOutputMode OutputMode { get; set; } Source

Gets or sets how the console app should balance command-owned output against ambient host lifecycle diagnostics.

Remarks

The default value is ConsoleOutputMode.Default, which preserves the standard Generic Host behavior. Set this to ConsoleOutputMode.CommandFirst for public CLI tools whose help, validation, and progress output should stay command-centric.

Property

CustomRegistrations

List<Action<IServiceCollection>> CustomRegistrations { get; } Source

Gets custom service registrations that should be applied after AppSurface's built-in console services.

Remarks

Use this for advanced console hosting scenarios, such as injecting a custom CliFx.Infrastructure.IConsole implementation or additional logging providers for tests and embedded hosts.

Type

CommandService

Source
Method

CheckForUnknownOptions

void CheckForUnknownOptions(IConsole console) Source

Analyzes the current command-line arguments to detect unknown or mistyped options after a command has failed and, when possible, displays suggestions for valid alternatives.

Parameters

  • consoleThe console used to write diagnostic messages and option suggestions to the user.

Remarks

This method performs three main steps:
  1. Resolves the target command type from the parsed arguments and registered commands.
  2. Extracts the set of valid option names for the resolved command.
  3. Compares the provided arguments against the valid options and uses IOptionSuggester to present suggestions for any unknown options.
Type

IOptionSuggester

Source

Defines a contract for suggesting alternative options when an unknown option is provided.

Remarks

Use this abstraction when command parsing should improve interactive UX for unpredictable user-typed options or dynamic option sets without coupling callers to a specific matching algorithm. Prefer direct parser validation, explicit enum checks, or fixed lookup errors for tiny static option sets and strict non-interactive flows where suggestions add noise instead of recovery value.

Method

GetSuggestions

IReadOnlyList<string> GetSuggestions(string? unknownOption, IEnumerable<string>? validOptions) Source

Gets a list of suggested options based on the unknown option and the list of valid options.

Parameters

  • unknownOptionThe unknown option provided by the user, or null when parsing did not identify one.
  • validOptionsThe valid options for the current command, or null when none are available.

Returns

A non-null collection of suggested options.

Remarks

GetSuggestions implementations should treat a null or empty unknownOption, or a null or empty validOptions sequence, as producing no suggestions. The returned IReadOnlyList{T} must be non-null, should not contain duplicates, and should be deterministic: relevance-first when a scorer exists, then alphabetical for ties. Use this method for recovery hints, not as the source of truth for whether an option is valid.

Type

ConsoleStartup<TModule>

Source

A base class for console application startup logic, extending the module-based initialization.

Type Parameters

  • TModuleThe type of the root module.
Method

WithOptions

ConsoleStartup<TModule> WithOptions(Action<ConsoleOptions>? configureOptions = null) Source

Registers an optional callback to customize ConsoleOptions and enables fluent chaining.

Parameters

  • configureOptionsAn optional action invoked before startup context creation to modify console startup behavior.

Returns

The same ConsoleStartup{TModule} instance to support fluent configuration.

Method

RunAsync

Task RunAsync(string[] args) Source

Runs the console application asynchronously using a startup context derived from the supplied arguments and configured console options.

Parameters

  • argsCommand-line arguments supplied to the console application.

Returns

A task that completes when the host run finishes.

Method

ConfigureAdditionalServices

void ConfigureAdditionalServices(StartupContext context, IServiceCollection services) Source

Allows derived classes to register additional services.

Parameters

  • contextThe startup context.
  • servicesThe service collection.
Type

ConsoleApp<TStartup, TModule>

Source

This class is used to run a console application with a specified startup class and module. This allows for further customization of the consoles startup process.

Method

RunAsync

Task RunAsync(string[] args, Action<ConsoleOptions>? configureOptions = null) Source

Runs the console application asynchronously using a custom startup class.

Parameters

  • argsCommand-line arguments.
  • configureOptionsAn optional delegate to customize ConsoleOptions before startup.

Returns

A task representing the run operation.

Type

ConsoleApp<TModule>

Source

This class is used to run a console application with a specified module and a generic startup.

Type Parameters

  • TModuleThe type of the root module.
Method

RunAsync

Task RunAsync(string[] args, Action<ConsoleOptions>? configureOptions = null) Source

Runs the console application asynchronously with a generic startup.

Parameters

  • argsCommand-line arguments.
  • configureOptionsAn optional delegate to customize ConsoleOptions before startup.

Returns

A task representing the run operation.

Type

ChainedCommand

Source

A command that can execute a sequence of other commands. Parameters and options defined on the parent command are automatically forwarded to the child commands when they share the same property name. Required parameters of child commands are validated before any command in the chain is executed.

Method

Configure

void Configure(CommandChainBuilder builder) Source

Configures the sequence of commands to execute.

Parameters

  • builderFluent builder to define the chain.
Type

CommandChainBuilder

Source

Fluent builder used to configure the chain of commands.

Method

Add

CommandChainBuilder Add<TCommand>() Source

Adds a command to the execution chain.

Method

AddIf

CommandChainBuilder AddIf<TCommand>(Func<bool> condition) Source

Adds a command to the chain that will execute only when condition returns true.

Type

LevenshteinOptionSuggester

Source

Suggests options using the Levenshtein distance algorithm.

Method

GetSuggestions

IReadOnlyList<string> GetSuggestions(string? unknownOption, IEnumerable<string>? validOptions) Source

Gets a list of suggested options based on their Levenshtein distance to the unknown option.

Parameters

  • unknownOptionThe unknown command line option.
  • validOptionsThe list of valid command line options.

Returns

A collection of suggested options that closely match the unknown option.

Method

ComputeLevenshteinDistance

int ComputeLevenshteinDistance(string s, string t) Source

Computes the Levenshtein distance between two strings using a dynamic programming approach.

Parameters

  • sThe first string to compare.
  • tThe second string to compare.

Returns

The number of single-character edits (insertions, deletions, or substitutions) required to change one string into the other.