Lightweight CLI framework for Python projects with automatic command discovery
Project description
clicommands
Lightweight Python library for managing command-line commands with automatic discovery.
Features
- Automatic command discovery via
commands/directory or.commands.json - Two ways to define commands: function suffixed with
_commandorCommandclass - Argument parsing API:
classify_args,parse_args_from_config - Envfile loading:
ENVFILE_PATHsupport for loading.env - Built-in commands:
version,copy,varenv
Installation
pip install clicommands
Quick Start
- Create a
cli.pyin your package:
import sys
from pathlib import Path
from clicommands.helpers import cli_main
def main(argv=None):
cli_file_path = Path(__file__)
result = cli_main(cli_file_path, argv)
return int(result) if isinstance(result, (int, bool)) else (0 if result else 1)
if __name__ == "__main__":
sys.exit(main())
- Add a
commands/directory with your commands:
# commands/hello.py
def hello_command(args: list[str]) -> bool:
"""Say hello."""
print("Hello, world!")
return True
- Run:
python -m mypackage.cli hello
.commands.json Configuration
{
"packages": ["other_package"],
"directories": ["commands"],
"commands": []
}
packages: Packages to import commands fromdirectories: Paths to command directoriescommands: Additional commands
Documentation
docs/purpose.md— Purpose and use casesdocs/structure.md— Project organizationdocs/development.md— Development guidelinesdocs/AI.md— AI assistant contract
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
clicommands-0.1.1.tar.gz
(14.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file clicommands-0.1.1.tar.gz.
File metadata
- Download URL: clicommands-0.1.1.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
264733ca343258e10f361d0a44889eb25d4fbcc666d86209886f688f04d6c3d4
|
|
| MD5 |
2d9dc582f40d80698e0640df4a247e7f
|
|
| BLAKE2b-256 |
42f6c0c4e4b4575eab4a7419abbc7a9a9c47e585c60730dfbe91c205f41ede83
|
File details
Details for the file clicommands-0.1.1-py3-none-any.whl.
File metadata
- Download URL: clicommands-0.1.1-py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d90692dcb23138cd393e9315fba4dbd39e3ac8db604f291b4c16ebbb7430e5b3
|
|
| MD5 |
c444e43dac1d3771f3c1cbddb0a109c7
|
|
| BLAKE2b-256 |
fd81a288e533bae8d44803356c468eaf7663c28517926f03093a0120ae42746e
|