Commands¶
Copa's command system is built around dynamic registration from your toc.yml configuration file.
How Commands Work¶
- Definition: Commands are defined in
copa/conf/toc.yml - Loading: Configuration is loaded at startup via
copa/core/toc.py - Registration: Commands are dynamically registered using
copa/core/typer.py - Execution: Commands are executed via
copa/core/execute.py
Command Syntax¶
copa <command> <subcommand> [options]
Global Options¶
-v, --verbose: Increase verbosity (can be used multiple times)--help: Show help information
Verbosity Levels¶
- 0 (default): ERROR and CRITICAL only
- 1 (
-v): WARNING and above - 2 (
-vv): INFO and above - 3 (
-vvv): DEBUG and above
Command Discovery¶
List all available commands:
copa --help
Get help for a specific command:
copa mycommand --help
Command Execution Flow¶
For Ansible Playbooks¶
- Copa identifies the playbook file
- Validates the file exists
- Executes using
ansible-runner - Streams output with appropriate logging level
For Python Functions¶
- Copa imports the specified module
- Calls the function with any provided arguments
- Handles return values and exceptions
- Logs execution details
Error Handling¶
Copa provides comprehensive error handling:
- Configuration errors: Invalid
toc.ymlsyntax - Missing files: Playbook files that don't exist
- Import errors: Python modules that can't be loaded
- Execution errors: Runtime failures in playbooks or functions
All errors are logged with appropriate detail levels based on verbosity settings.