This template repository was developed to bootstrap the initial creation process of CLIs and provides the following features out of the box:
- GitHub Action workflows for unit tests, static code analyses and deployment to PyPI
- a
Logger
helper class as a thin wrapper around the standardlogging
module - provides some starter code for handling configuration files by using the standard
configparser
module - some starter code for advanced command line applications using
click
- also integrates very well with
rich
Click on the Use this template
button to create a new repository and install the project in a virtual environment:
python -m venv venv/
.\venv\Scripts\Activate.ps1
pip install -e .
pip install -r requirements/dev.txt
You can use the configure.ps1
script in the scripts
directory to help you
customize this application:
.\scripts\configure.ps1
Alternatively, you can make these changes yourself by editing the
src/clitemplate/__init__.py
file. Note that you should also rename the clitemplate
folder in the src
directory to match your package_name
. For terminal applications
specifically, take into account the following recommendations:
- use short and concise names for CLI programs
- avoid generic names that could cause a conflict with established standard tools
- avoid special characters such as
-
or_
in your application name
The starter code implements a standard interface to help you get started with writing your own commands:
# the package name also declares the entry point of the application
# remember: you should always implement the help and version flag
clitemplate --help
clitemplate --version
# the square function is implemented as a subcommand here
# it is considered good practice to provide an optional verbose flag
clitemplate --verbose square --xmin <int> --xmax <int>
You can also install this project with pipx
if you don't want to deploy this project on PyPI:
python -m pip install pipx
pipx install git+https://github.com/Advanced-Systems/cli-template.git