Skip to main content

Enable grouping and ordering of commands.

Project description

click-groups

License PyPI Python Version CI codecov

Enable grouping and ordering of commands.

Would you like to split your commands into sub-groups so that they are nicely organized? Or perhaps you would like to ensure that the order of your commands stays consistent?

Now you can do this by specifying few additional group attributes.

In your click app:

import click
from click_groups import GroupedGroup

@click.group(cls=GroupedGroup)
def cli():
    pass

@cli.command(help_group="Group 1", priority=10)
def command_1():
    """Run a command."""

@cli.command(help_group="Group 1")
def command_2():
    """Run a command."""

@cli.command(help_group="Group 2")
def command_3():
    """Run a command."""

@cli.command(help_group="Group 3")
def command_4():
    """Run a command."""

@cli.command()
def command_5():
    """Run a command."""

@click.group(cls=GroupedGroup)
def command_6():
    """Run a command."""

cli.add_command(command_6)

@click.group(cls=GroupedGroup)
def command_7():
    """Run a command."""

cli.add_command(command_7, help_group="Group 1", priority=0)

Which will result in:

Usage: cli [OPTIONS] COMMAND [ARGS]...

Options:
  --help  Show this message and exit.

Group 1:
  command-7  Run a command.
  command-2  Run a command.
  command-1  Run a command.

Group 2:
  command-3  Run a command.

Group 3:
  command-4  Run a command.

Commands:
  command-5  Run a command.
  command-6  Run a command.

Contributing

Contributions are always welcome. Please feel free to submit PRs with new features, bug fixes, or documentation improvements.

git clone https://github.com/lukasz-migas/click-groups.git

pip install -e .[dev]

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-groups-0.1.1.tar.gz (9.7 kB view hashes)

Uploaded Source

Built Distribution

click_groups-0.1.1-py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 3

Supported by

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