diff --git a/Readme.md b/Readme.md index 5f0444dde..6434770ba 100644 --- a/Readme.md +++ b/Readme.md @@ -730,6 +730,8 @@ The supported events are: | `preAction`, `postAction` | before/after action handler for this command and its nested subcommands | `(thisCommand, actionCommand)` | | `preSubcommand` | before parsing direct subcommand | `(thisCommand, subcommand)` | +For an overview of the life cycle events see [parsing life cycle and hooks](./docs/parsing-and-hooks.md). + ## Automated help The help information is auto-generated based on the information commander already knows about your program. The default @@ -1114,6 +1116,7 @@ There is more information available about: - [deprecated](./docs/deprecated.md) features still supported for backwards compatibility - [options taking varying arguments](./docs/options-taking-varying-arguments.md) +- [parsing life cycle and hooks](./docs/parsing-and-hooks.md) ## Support diff --git a/docs/parsing-and-hooks.md b/docs/parsing-and-hooks.md new file mode 100644 index 000000000..122cad6f7 --- /dev/null +++ b/docs/parsing-and-hooks.md @@ -0,0 +1,23 @@ +# Parsing life cycle and hooks + +The processing starts with an array of args. Each command processes and removes the options it understands, and passes the remaining args to the next subcommand. +The final command calls the action handler. + +Starting with top-level command (program): + +- parse options: parse recognised options (for this command) and remove from args +- parse env: look for environment variables (for this command) +- process implied: set any implied option values (for this command) +- if the first arg is a subcommand + - call `preSubcommand` hooks + - pass remaining arguments to subcommand, and process same way + +Once reach final (leaf) command: + +- check for missing mandatory options +- check for conflicting options +- check for unknown options +- process remaining args as command-arguments +- call `preAction` hooks +- call action handler +- call `postAction` hooks