Skip to main content

PyPI Python Versions Build Status Coverage Status Code Quality

Rapidly create full-featured command line interfaces with help, subcommand dispatch, and validation.

rcli uses docopt to give you the control over your usage messages that you want, but adds functionality such as automatic subcommand dispatching, usage string wrapping, internationalization, and parameter validation.

Installation

Install it using pip:

pip install rcli

Features

  • Automatic creation of console scripts and entry points based on usage strings.

  • Argument parsing based on usage string.

  • Usage string wrapping.

  • Command line arguments are normalized into python function parameters.

  • Validation of command line arguments using PEP 484 type hints.

  • Logging with multiple levels and crash log generation.

  • Color coded logging based on log level.

  • Extensible subcommand generation based on entry point groups.

Upcoming Features

  • Automatic generation of bash and zsh autocompletion scripts.

  • Internationalization of usage strings.

Basic Usage

To use rcli, add rcli to your setup_requires argument in your setup.py and set the autodetect_commands parameter to True.

from setuptools import setup
setup(
    ...,
    install_requires=['rcli'],
    setup_requires=['rcli'],
    autodetect_commands=True,
    ...,
)

In your code, create a function with a usage string as its docstring and type hint annotations for validation.

def repeat(message: str, num_times: int):
    """Usage: repeat <message> [--num-times <num>]

    Arguments:
        message  A message to print to the console.

    Options:
        -n, --num-times <num>  The number of times to print the message [default: 1].
    """
    for i in range(num_times):
        print(message)

Once your package is installed, a new console script repeat will be automatically generated that will validate and normalize your parameters and call your function.

Subcommand Dispatch

To generate a git-style command line interface with subcommand dispatching, you only need to create your subcommand functions and your primary command will be automatically generated for you.

def roar():
    """Usage: cat-sounds roar"""
    print('ROAR!')

def meow():
    """Usage: cat-sounds meow"""
    print('Meow!')

This automatically generates the command cat-sounds with the following help message:

Usage:
  cat-sounds [--help] [--version] [--log-level <level> | --debug | --verbose]
             <command> [<args>...]

Options:
  -h, --help           Display this help message and exit.
  -V, --version        Display the version and exit.
  -d, --debug          Set the log level to DEBUG.
  -v, --verbose        Set the log level to INFO.
  --log-level <level>  Set the log level to one of DEBUG, INFO, WARN, or ERROR.

'cat-sounds help -a' lists all available subcommands.
See 'cat-sounds help <command>' for more information on a specific command.

Release files for rcli 0.5.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rcli 0.5.2
File Size Uploaded
rcli-0.5.2.tar.gz 33.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rcli 0.5.2
File Interpreter ABI Platform
rcli-0.5.2-py3-none-any.whl Python 3 none any Details

Total release size:60.2 kB

Release files / rcli-0.5.2.tar.gz

Download URL rcli-0.5.2.tar.gz
Size 33.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ee2198aa91052a4487b96f399dcec583a8d33a26f08b810c9db18690476e5a3e
BLAKE2b-256 checksum
How to use checksums
f9161eebcd8095d6d4df41b962cfa2137ee7bbebb0bcf8f2af0e079d0a090782
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

Release files / rcli-0.5.2-py3-none-any.whl

Download URL rcli-0.5.2-py3-none-any.whl
Size 26.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9ff016c85c8cee357ecb8fcde7efd08e9231fcb5558c24f89997136933be2815
BLAKE2b-256 checksum
How to use checksums
a47127349b23e557e9612e3a8095d75892c8cb78a8155ca596f77805ad73cf1f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.3

Release history Release notifications | RSS feed

This release

0.5.2 This release

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.6

2 release files

0.2.5

2 release files

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page