-
Notifications
You must be signed in to change notification settings - Fork 13
CLI Modes
Since Typin 3.0 an ability to define custom CLI modes was added. The changes included new services and interfaces:
-
ICliCommandExecutor
- CLI command executor. CallingICliCommandExecutor.ExecuteCommandAsync
creates a new DI scope and executes a command-line. A scope is defined as a lifetime of a command execution pipeline that includes directives handling. -
ICliMode
- CLI mode definition abstraction with a single method -ExecuteAsync
that passes command-line arguments fromRunAsync
and a command executor instance. -
ICliApplicationLifetime
- provides methods to switch and get the current CLI mode. It also provides aRequestStop
method that can be used to safely shutdown the app.
A mode in which the application has started can be obtained with
ApplicationConfiguration.StartupMode
. Only one mode can be marked as a startup mode, and if no mode was registered or none of the registered modes was marked as startup, DirectMode will be registered.
CLI modes are always switched after executing a command, and they can abort stop requests.
CliApplicationBuilder
provides aRegisterMode
method but it should not be used directly when configuring the app, instead callUseXMode
method, e.g.UseDirectMode()
.
Commands and directives can be restricted to run or not to run in some modes with:
-
SupportedModes
- a list of CLI mode types, in which the command can be executed. If null (default) or empty, command can be executed in every registered mode in the app. -
ExcludedModes
a list of CLI mode types, in which the command cannot be executed. If null (default) or empty, command can be executed in every registered mode in the app.
Getting started
Advanced features
- Reporting errors
- Exception handling
- Metadata and startup message
- Graceful cancellation
- Dependency injection
- Middleware pipeline
- Environment variables
Utilities
Tests
Misc