click-option-group

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).

Installing

You can install and update click-option-group using pip:

pip install -U click-option-group

Quickstart

Here is a simple example how to use option groups in your Click-based CLI.

import click
from click_option_group import optgroup

@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')
@click.option('--debug/--no-debug', default=False, help='Debug flag')
def cli(host, port, debug):
     print(params)

if __name__ == '__main__':
    cli()

Contents

Indices and tables