Skip to main content

Enable grouping and ordering of commands.

Project description

click-groups

License PyPI Python Version CI codecov

Enable grouping, ordering and aliasing 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? Or maybe you would like to provide aliases for your commands?

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():
    """Run commands."""


@cli.command(help_group="Group 1", priority=10)
def command_low_priority():
    """Run a command."""
    click.echo("Low priority command.")


@cli.command(help_group="Group 1", aliases=["medium", "m"])
def command_medium_priority():
    """Run a command."""
    click.echo("Medium priority command.")


@cli.command(help_group="Group 1", priority=0, aliases=["high", "h"])
def command_high_priority():
    """Run a command."""
    click.echo("High priority command.")


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


@command_3.command(help_group="Group 2", aliases=["sub1"])
def subcommand_1():
    """Run a command."""


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


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


@cli.group()
def command_6():
    """Run a command."""

Which will result in:

Usage: simple.py [OPTIONS] COMMAND [ARGS]...

  Run commands.

Options:
  --help  Show this message and exit.

Group 1:
  command-high-priority (h,high)  Run a command.
  command-medium-priority (m,medium)
                                  Run a command.
  command-low-priority            Run a command.

Group 3:
  command-4  Run a command.

Commands:
  command-5  Run a command.
  command-3  Group 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.4.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

click_groups-0.1.4-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file click_groups-0.1.4.tar.gz.

File metadata

  • Download URL: click_groups-0.1.4.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for click_groups-0.1.4.tar.gz
Algorithm Hash digest
SHA256 3c8e4914cb3417b910a3f965ea279e17c75ed517c42445015bc5df05a31fc294
MD5 d7db5ba214239c59824d6cb06d258a12
BLAKE2b-256 4ed526675ae28c84ef45ad6a76b68d425729922c75eaaa4bcd7c87e01dde2f7f

See more details on using hashes here.

File details

Details for the file click_groups-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for click_groups-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f4f15ad3b1f48883ea8add16744261de8cd79b528c8102fa3b5480264c5286b1
MD5 4c20131493edd3a0c45d01a5ee58d6ee
BLAKE2b-256 0904eff8c7a2dba86e0bbac8cebd9c10ccdf3dcba2817f30ac92dda123309063

See more details on using hashes here.

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