Skip to content

Example: Hooks

Source: examples/hooks/

Shows how to use CliOptions.hooks to run code at lifecycle events:

  • beforeParse: validate environment variables before parsing arguments
  • afterParse: log the parsed output
  • beforeExecute: authentication check — throws to prevent execution
  • afterExecute: cleanup, always called even if beforeExecute threw

See Features → Lifecycle hooks for the full diagram.

Released under the MIT License.