Command Lifecycle and Execution Flow

An explanatory deep-dive into what happens from the moment app.Run(args) is called to when a command finishes execution

An explanatory deep-dive into what happens from the moment app.Run(args) is called to when a command finishes execution. It describes:

  • Parsing Phase: how the arguments array is parsed against the configured commands and settings, how Spectre.Console.Cli matches arguments to CommandSettings properties (and provides errors if something is wrong).
  • Validation Phase: how and when the library calls Validate() on settings or commands (e.g., does it validate CommandSettings by invoking an optional Validate method on settings class or just the command's override as documented).
  • Execution Phase: how the appropriate Command instance is constructed (using DI if available), then Execute or ExecuteAsync is called.
  • Post-Execution: handling the result (the int exit code) and any exception propagation or interception.
  • Help invocation: mention that if --help is detected, the above phases short-circuit to display help instead of executing a command. This explanation might include a simple flow diagram or description: Input args -> Parser selects Command -> Settings populated -> If parse errors, show error/help -> If ok, create Command -> (Interceptor before) -> Execute -> (Interceptor after) -> return exit code. By understanding this flow, users can reason about behaviors like why their code in Execute might not run (e.g. if parsing failed or validation failed first).