Subcommands
Project-specific CLI commands are defined in the dev/cli/subcommands.py
module. All public functions in this module are automatically registered as CLI
commands.
Defining Commands
Add a public function to subcommands.py to create a new command. The function
name becomes the command name (underscores are converted to hyphens), and the
docstring becomes the help text.
Use typer.Option to add command-line options with flags. See the existing
commands in pyrig/dev/cli/subcommands.py for examples.
Command Pattern
Follow this pattern for all subcommands:
- Define a wrapper function in
subcommands.py - Use lazy imports to avoid circular dependencies and missing dev dependencies
- Delegate to implementation in
dev/cli/commands/ - Add a docstring for CLI help text
Automatic Registration
The CLI system automatically discovers and registers three types of commands:
- Main entry point - The
main()function from<package>.main - Subcommands - All public functions from
<package>.dev.cli.subcommands - Shared subcommands - All public functions
from
<package>.dev.cli.shared_subcommandsacross all packages in the dependency chain (see Shared Subcommands)
Functions are discovered and registered automatically:
- No manual registration required
- Functions only - classes and variables are ignored
- Defined in module - imported functions are excluded
- Sorted by definition order - commands appear in the order they're defined
For implementation details on command discovery, see the docstrings in
pyrig/dev/cli/cli.py.
Command Naming
Function names are converted to CLI command names:
mkroot→pyrig mkrootmktests→pyrig mktestsprotect_repo→pyrig protect-repo
Multi-Package Support
When a package depends on pyrig, it can define its own subcommands:
myapp/
dev/
cli/
subcommands.py # Define myapp-specific commands here
Running uv run myapp <command> will discover and execute commands from
myapp.dev.cli.subcommands.
Built-in Commands
pyrig includes these built-in subcommands:
init- Complete project setupmkroot- Create project structure and config filesmktests- Generate test skeletonsmkinits- Create__init__.pyfilesbuild- Build all artifactsprotect-repo- Configure repository protection
pyrig also includes this shared subcommand (available in all dependent projects):
version- Display the current project's version