Helpers to build a CLI program and some useful tools for CLI programs.
pip install cli-base-utilities
Some of the features are:
TODO: Document all features here ;)
~$ git clone https://github.com/jedie/cli-base-utilities.git
~$ cd cli-base-utilities
~/cli-base-utilities$ ./dev-cli.py --help
usage: ./dev-cli.py [-h]
{check-code-style,coverage,fix-code-style,install,mypy,pip-audit,publish,test,
tox,update,update-test-snapshot-files,version}
╭─ options ──────────────────────────────────────────────────────────────────────────────────────╮
│ -h, --help show this help message and exit │
╰────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ subcommands ──────────────────────────────────────────────────────────────────────────────────╮
│ {check-code-style,coverage,fix-code-style,install,mypy,pip-audit,publish,test,tox,update,upda… │
│ check-code-style │
│ Check code style by calling darker + flake8 │
│ coverage Run tests and show coverage report. │
│ fix-code-style │
│ Fix code style of all cli_base source code files via darker │
│ install Run pip-sync and install 'cli_base' via pip as editable. │
│ mypy Run Mypy (configured in pyproject.toml) │
│ pip-audit Run pip-audit check against current requirements files │
│ publish Build and upload this project to PyPi │
│ test Run unittests │
│ tox Run tox │
│ update Update "requirements*.txt" dependencies files │
│ update-test-snapshot-files │
│ Update all test snapshot files (by remove and recreate all snapshot files) │
│ version Print version and exit │
╰────────────────────────────────────────────────────────────────────────────────────────────────╯
usage: ./cli.py [-h] {update-readme-history,version}
╭─ options ──────────────────────────────────────────────────────────────────────────────────────╮
│ -h, --help show this help message and exit │
╰────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ subcommands ──────────────────────────────────────────────────────────────────────────────────╮
│ {update-readme-history,version} │
│ update-readme-history │
│ Update project history base on git commits/tags in README.md Will be exited │
│ with 1 if the README.md was updated otherwise with 0. │
│ │
│ Also, callable via e.g.: │
│ python -m cli_base update-readme-history -v │
│ version Print version and exit │
╰────────────────────────────────────────────────────────────────────────────────────────────────╯
usage: ./cli.py [-h]
{demo-endless-loop,demo-verbose-check-output-error,edit-settings,print-settings,sy
stemd-debug,systemd-remove,systemd-setup,systemd-status,systemd-stop,version}
╭─ options ──────────────────────────────────────────────────────────────────────────────────────╮
│ -h, --help │
│ show this help message and exit │
╰────────────────────────────────────────────────────────────────────────────────────────────────╯
╭─ subcommands ──────────────────────────────────────────────────────────────────────────────────╮
│ {demo-endless-loop,demo-verbose-check-output-error,edit-settings,print-settings,systemd-debug… │
│ demo-endless-loop │
│ Just a useless example command, used in systemd DEMO: It just print some information in a │
│ endless loop. │
│ demo-verbose-check-output-error │
│ DEMO for a error calling cli_base.cli_tools.subprocess_utils.verbose_check_output() │
│ edit-settings │
│ Edit the settings file. On first call: Create the default one. │
│ print-settings │
│ Display (anonymized) MQTT server username and password │
│ systemd-debug │
│ Print Systemd service template + context + rendered file content. │
│ systemd-remove │
│ Write Systemd service file, enable it and (re-)start the service. (May need sudo) │
│ systemd-setup │
│ Write Systemd service file, enable it and (re-)start the service. (May need sudo) │
│ systemd-status │
│ Display status of systemd service. (May need sudo) │
│ systemd-stop │
│ Stops the systemd service. (May need sudo) │
│ version │
│ Print version and exit │
╰────────────────────────────────────────────────────────────────────────────────────────────────╯
Add a test case similar to cli_base/tests/test_readme_history.py into your project.
Add the needed start
/end
comments into your README.
To make a new release, do this:
It's recommended to use git hookd (via pre-commit) to update the README.
For this, add in your pyproject.toml
:
[tool.cli_base]
version_module_name = "<your_package>" # Must provide the `__version__` attribute
Copy&paste .pre-commit-config.yaml into your project.
Add pre-commit
to your requirements and install the git hooks by:
.venv/bin/pre-commit install
.venv/bin/pre-commit autoupdate
Update version in .pre-commit-config.yaml
and make a release.
The Problem: The hooks are broken, if the "new" version is not tagged yet.
To create a release, it's possible to use all git commands (commit, push, etc) with --no-verify
to skip the hooks.
It's easier to temporarily uninstall the hooks, create the release and install the hooks again, e.g.:
.../cli-base-utilities$ .venv/bin/pre-commit uninstall
# ...bump version, commit, push, merge... create release...
.../cli-base-utilities$ .venv/bin/pre-commit install