Skip to main content

CLI Command Parser

Project description

downloads py_version coverage_badge build_status Blue

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 (default: False)

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]

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

cli_command_parser-2023.1.14.tar.gz (93.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cli_command_parser-2023.1.14-py3-none-any.whl (114.1 kB view details)

Uploaded Python 3

File details

Details for the file cli_command_parser-2023.1.14.tar.gz.

File metadata

  • Download URL: cli_command_parser-2023.1.14.tar.gz
  • Upload date:
  • Size: 93.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for cli_command_parser-2023.1.14.tar.gz
Algorithm Hash digest
SHA256 3681272e809bd2c02a20f7116d1f4fe30843a0b8a35bb4956951ac75b1b173f9
MD5 77c8fa8e0e0594f4b8b1a1d62cef3ce2
BLAKE2b-256 944a97e1b7083710ca06fb2b76a27f973fd94c67c11a8350ecdc93ac2c4a359c

See more details on using hashes here.

File details

Details for the file cli_command_parser-2023.1.14-py3-none-any.whl.

File metadata

File hashes

Hashes for cli_command_parser-2023.1.14-py3-none-any.whl
Algorithm Hash digest
SHA256 7fb90f07de8c88ecc8957667812ff4bcac9bf6c726649171383d1ea50683e18e
MD5 7c2d4c528994ebb1b801d73245feabcd
BLAKE2b-256 ca225b45eef8a30e108d2efdefad5be38ffdb516291f8ef8259059784bd409a8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page