A Python CLI template that has two roles in one repo:
cli_foundation: reusable CLI/runtime plumbingcli_template: generator for new projects
src/cli_foundation/with reusable CLI bootstrap, config, logging, checks, and the sharedconfigcommandsrc/cli_template/with the template app and theinitgenerator command- dynamic command discovery from command packages
- global
--versionand--verboseflags - an
initcommand that creates a new thin CLI project - tests for both the shared runtime behavior and generator behavior
Makefiletargets for install, format, lint, typecheck, and test
Create a new CLI project:
make install
.venv/bin/cli-template
.venv/bin/cli-template init /tmp/my-new-cli . # Name derived from path
.venv/bin/cli-template init /tmp/my-new-cli --name "Different name" # Or be explicit
# Reinitialize an existing clean git repository destination
.venv/bin/cli-template init /tmp/existing-project --reinitialize
# Bypass clean-repo reinitialize safeguards explicitly
.venv/bin/cli-template init /tmp/existing-project --reinitialize --forceGenerated projects now stay thin:
- app-specific code is generated into the new project
- shared runtime code is not copied into the new project
- the generated project depends on this package for shared CLI behavior
src/
cli_foundation/
cli.py
config.py
logging.py
checks/
commands/
cli_template/
cli.py
project_init.py
commands/
templates/
tests/
- Put reusable CLI/runtime behavior in
cli_foundation. - Keep project generation and
initbehavior incli_template. - Let generated apps own only app-specific commands and business logic.
The reusable import package is cli_foundation, while the generated-project
dependency currently points at the distribution published from this repo. This
is mostly for one-dev convenience, this can be split/renamed in the future if
necessary.