Console
ForgeTrust.Runnable.Console
Modular bootstrapping for .NET Console applications using CliFx.
Overview
ForgeTrust.Runnable.Console provides a structured way to build command-line tools. It automatically discovers and registers CliFx commands from modules and provides a hosted service to run them.
Usage
Create a startup class that inherits from ConsoleStartup<TModule>:
public class MyConsoleStartup : ConsoleStartup<MyRootModule> { }
In your Program.cs:
await ConsoleApp<MyRootModule>.RunAsync(args);
Features
- Command Discovery: Automatically registers classes implementing
ICommandfrom the entry point assembly and dependent modules. - Hosted Runner: Integrates with the .NET Generic Host to manage service lifecycles during command execution.
ConsoleApp<TStartup, TModule>
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.
RunAsync
Task RunAsync(string[] args)
Runs the console application asynchronously using a custom startup class.
Parameters
argsCommand-line arguments.
Returns
A task representing the run operation.
ConsoleApp<TModule>
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.
RunAsync
Task RunAsync(string[] args)
Runs the console application asynchronously with a generic startup.
Parameters
argsCommand-line arguments.
Returns
A task representing the run operation.
ChainedCommand
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.
Configure
void Configure(CommandChainBuilder builder)
Configures the sequence of commands to execute.
Parameters
builderFluent builder to define the chain.
CommandChainBuilder
Fluent builder used to configure the chain of commands.
Add
CommandChainBuilder Add<TCommand>()
Adds a command to the execution chain.
AddIf
CommandChainBuilder AddIf<TCommand>(Func<bool> condition)
Adds a command to the chain that will execute only when condition returns true.
ConsoleStartup<TModule>
A base class for console application startup logic, extending the module-based initialization.
Type Parameters
TModuleThe type of the root module.
ConfigureAdditionalServices
void ConfigureAdditionalServices(StartupContext context, IServiceCollection services)
Allows derived classes to register additional services.
Parameters
contextThe startup context.servicesThe service collection.