CLI Command Parser
Project description
CLI Command Parser is a class-based CLI argument parser that defines parameters with descriptors. It provides the tools to quickly and easily get started with basic CLIs, and it scales well to support even very large and complex CLIs while remaining readable and easy to maintain.
- The primary goals of this project:
Make it easy to define subcommands and actions in an clean and organized manner
Allow for inheritance so that common parameters don’t need to be repeated
Make it easy to handle common initialization tasks for all actions / subcommands once
Reduce the amount of boilerplate code that is necessary for setting up parsing and handling argument values
Example Program
from cli_command_parser import Command, Option, main
class Hello(Command, description='Simple greeting example'):
name = Option('-n', default='World', help='The person to say hello to')
count: int = Option('-c', default=1, help='Number of times to repeat the message')
def main(self):
for _ in range(self.count):
print(f'Hello {self.name}!')
if __name__ == '__main__':
main()
$ hello_world.py --name Bob -c 3
Hello Bob!
Hello Bob!
Hello Bob!
$ hello_world.py -h
usage: hello_world.py [--name NAME] [--count COUNT] [--help]
Simple greeting example
Optional arguments:
--name NAME, -n NAME The person to say hello to (default: 'World')
--count COUNT, -c COUNT Number of times to repeat the message (default: 1)
--help, -h Show this help message and exit
Installing CLI Command Parser
CLI Command Parser can be installed and updated via pip:
$ pip install -U cli-command-parser
There are no required dependencies. Support for formatting wide characters correctly in help text descriptions can be included by adding wcwidth to your project’s requirements, and/or by installing with optional dependencies:
$ pip install -U cli-command-parser[wcwidth]
Python Version Compatibility
Python versions 3.9 and above are currently supported. The last release of CLI Command Parser that supported 3.8 was 2024-09-07. Support for Python 3.8 officially ended on 2024-10-07.
Links
Documentation: https://dskrypa.github.io/cli_command_parser/
Example Scripts: https://github.com/dskrypa/cli_command_parser/tree/main/examples
PyPI Releases: https://pypi.org/project/cli-command-parser/
Source Code: https://github.com/dskrypa/cli_command_parser
Issue Tracker: https://github.com/dskrypa/cli_command_parser/issues
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
Built Distribution
File details
Details for the file cli_command_parser-2024.11.2.tar.gz
.
File metadata
- Download URL: cli_command_parser-2024.11.2.tar.gz
- Upload date:
- Size: 130.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f860fdc6e3b3adbd4d3f1ddac9d4308424e25fb102a45565f5ae6101a4249c1f |
|
MD5 | d08d6cb185e5c5fae144621297b29851 |
|
BLAKE2b-256 | 45c9f8a3341006e0dfe2867e731694bd77d876729ea725cacf2e316220e369ea |
File details
Details for the file cli_command_parser-2024.11.2-py3-none-any.whl
.
File metadata
- Download URL: cli_command_parser-2024.11.2-py3-none-any.whl
- Upload date:
- Size: 155.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 717d1c4e0a199326b8c1c6d5bec1bca2f3bf560713ade5e6ffbcc22cec604d71 |
|
MD5 | d0111de9aa09496ef43662596f8c6516 |
|
BLAKE2b-256 | 69bf2a7cf1b3f6dacab9aaedc784777866f8b3c2f1bc03ab7c7860953c8ec368 |