Skip to main content

Option groups missing in Click

Project description

click-option-group

PyPI version Build status Coverage Status Supported Python versions License

click-option-group is a Click-extension package that adds option groups missing in Click.

Aim and Motivation

Click is a package for creating powerful and beautiful command line interfaces (CLI) in Python, but it has no the functionality for creating option groups.

Option groups are convenient mechanism for logical structuring CLI, also it allows you to set the specific behavior and set the relationship among grouped options (mutually exclusive options for example). Moreover, argparse stdlib package contains this functionality out of the box.

At the same time, many Click users need this functionality. You can read interesting discussions about it in the following issues:

The aim of this package is to provide group options with extensible functionality using canonical and clean API (Click-like API as far as possible).

Quickstart

Installing

Install and update using pip:

pip install -U click-option-group

A Simple Example

Here is a simple example how to use option groups in your Click-based CLI. Just use optgroup for declaring option groups by decorating your command function in Click-like API style.

# app.py

import click
from click_option_group import optgroup, RequiredMutuallyExclusiveOptionGroup

@click.command()
@optgroup.group('Server configuration',
                help='The configuration of some server connection')
@optgroup.option('-h', '--host', default='localhost', help='Server host name')
@optgroup.option('-p', '--port', type=int, default=8888, help='Server port')
@optgroup.option('-n', '--attempts', type=int, default=3, help='The number of connection attempts')
@optgroup.option('-t', '--timeout', type=int, default=30, help='The server response timeout')
@optgroup.group('Input data sources', cls=RequiredMutuallyExclusiveOptionGroup,
                help='The sources of the input data')
@optgroup.option('--tsv-file', type=click.File(), help='CSV/TSV input data file')
@optgroup.option('--json-file', type=click.File(), help='JSON input data file')
@click.option('--debug/--no-debug', default=False, help='Debug flag')
def cli(**params):
    print(params)

if __name__ == '__main__':
    cli()
$ python app.py --help
Usage: app.py [OPTIONS]

Options:
  Server configuration:           The configuration of some server connection
    -h, --host TEXT               Server host name
    -p, --port INTEGER            Server port
    -n, --attempts INTEGER        The number of connection attempts
    -t, --timeout INTEGER         The server response timeout
  Input data sources: [mutually_exclusive, required]
                                  The sources of the input data
    --tsv-file FILENAME           CSV/TSV input data file
    --json-file FILENAME          JSON input data file
  --debug / --no-debug            Debug flag
  --help                          Show this message and exit.

Documentation

https://click-option-group.readthedocs.io

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

click_option_group-0.5.9.tar.gz (22.2 kB view details)

Uploaded Source

Built Distribution

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

click_option_group-0.5.9-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file click_option_group-0.5.9.tar.gz.

File metadata

  • Download URL: click_option_group-0.5.9.tar.gz
  • Upload date:
  • Size: 22.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for click_option_group-0.5.9.tar.gz
Algorithm Hash digest
SHA256 f94ed2bc4cf69052e0f29592bd1e771a1789bd7bfc482dd0bc482134aff95823
MD5 93038ab84615f17f80f6aedcdfcd02ad
BLAKE2b-256 efffd291d66595b30b83d1cb9e314b2c9be7cfc7327d4a0d40a15da2416ea97b

See more details on using hashes here.

Provenance

The following attestation bundles were made for click_option_group-0.5.9.tar.gz:

Publisher: release.yaml on click-contrib/click-option-group

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file click_option_group-0.5.9-py3-none-any.whl.

File metadata

File hashes

Hashes for click_option_group-0.5.9-py3-none-any.whl
Algorithm Hash digest
SHA256 ad2599248bd373e2e19bec5407967c3eec1d0d4fc4a5e77b08a0481e75991080
MD5 205ab63957552c54a1821a33c2ef3538
BLAKE2b-256 754554bb2d8d4138964a94bef6e9afe48b0be4705ba66ac442ae7d8a8dc4ffef

See more details on using hashes here.

Provenance

The following attestation bundles were made for click_option_group-0.5.9-py3-none-any.whl:

Publisher: release.yaml on click-contrib/click-option-group

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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