CLI Modes - adambajguz/Typin GitHub Wiki
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.ExecuteCommandAsynccreates 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 -ExecuteAsyncthat passes command-line arguments fromRunAsyncand a command executor instance.ICliApplicationLifetime- provides methods to switch and get the current CLI mode. It also provides aRequestStopmethod 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.
CliApplicationBuilderprovides aRegisterModemethod but it should not be used directly when configuring the app, instead callUseXModemethod, e.g.UseDirectMode().
Restricting commands and directives
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.ExcludedModesa 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.