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. Calling ICliCommandExecutor.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 from RunAsync and a command executor instance.
  • ICliApplicationLifetime - provides methods to switch and get the current CLI mode. It also provides a RequestStop 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 a RegisterMode method but it should not be used directly when configuring the app, instead call UseXMode method, 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.
  • 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.