ConsoleOptions Default { get; }
Source
Gets a default instance of ConsoleOptions
.
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.
void Configure(CommandChainBuilder builder)
Configures the sequence of commands to execute.
builder
Fluent builder used to configure the chain of commands.
CommandChainBuilder Add<TCommand>()
Adds a command to the execution chain.
CommandChainBuilder AddIf<TCommand>(Func<bool> condition)
Adds a command to the chain that will execute only when condition
returns true.
void CheckForUnknownOptions(IConsole console)
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.
console
IOptionSuggester
to present suggestions for any unknown options. 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.
Task RunAsync(string[] args, Action<ConsoleOptions>? configureOptions = null)
Runs the console application asynchronously using a custom startup class.
args
configureOptions
ConsoleOptions
before startup.A task representing the run operation.
This class is used to run a console application with a specified module and a generic startup.
TModule
Task RunAsync(string[] args, Action<ConsoleOptions>? configureOptions = null)
Runs the console application asynchronously with a generic startup.
args
configureOptions
ConsoleOptions
before startup.A task representing the run operation.
Represents configurable startup options for AppSurface console applications.
ConsoleOptions Default { get; }
Source
Gets a default instance of ConsoleOptions
.
ConsoleOutputMode OutputMode { get; set; }
Source
Gets or sets how the console app should balance command-owned output against ambient host lifecycle diagnostics.
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.
List<Action<IServiceCollection>> CustomRegistrations { get; }
Source
Gets custom service registrations that should be applied after AppSurface's built-in console services.
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.
Defines a contract for suggesting alternative options when an unknown option is provided.
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.
IReadOnlyList<string> GetSuggestions(string? unknownOption, IEnumerable<string>? validOptions)
Gets a list of suggested options based on the unknown option and the list of valid options.
unknownOption
null
when parsing did not identify one.validOptions
null
when none are available.A non-null collection of suggested options.
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.
Suggests options using the Levenshtein distance algorithm.
IReadOnlyList<string> GetSuggestions(string? unknownOption, IEnumerable<string>? validOptions)
Gets a list of suggested options based on their Levenshtein distance to the unknown option.
unknownOption
validOptions
A collection of suggested options that closely match the unknown option.
int ComputeLevenshteinDistance(string s, string t)
Computes the Levenshtein distance between two strings using a dynamic programming approach.
s
t
The number of single-character edits (insertions, deletions, or substitutions) required to change one string into the other.
A base class for console application startup logic, extending the module-based initialization.
TModule
ConsoleStartup<TModule> WithOptions(Action<ConsoleOptions>? configureOptions = null)
Registers an optional callback to customize ConsoleOptions
and enables fluent chaining.
configureOptions
The same ConsoleStartup{TModule}
instance to support fluent configuration.
Task RunAsync(string[] args)
Runs the console application asynchronously using a startup context derived from the supplied arguments and configured console options.
args
A task that completes when the host run finishes.
void ConfigureAdditionalServices(StartupContext context, IServiceCollection services)
Allows derived classes to register additional services.
context
services