click-default-group

click_default_group


License
Unlicense
Install
pip install click-default-group==1.1

Documentation

Click Default Group

Build Status

DefaultGroup is a subclass of click.Group. But it invokes the default subcommand instead of showing a help message when a subcommand is not passed.

Usage

Define a default subcommand by default=NAME:

import click
from click_default_group import DefaultGroup

@click.group(cls=DefaultGroup, default='foo', default_if_no_args=True)
def cli():
    pass

@cli.command()
def foo():
    click.echo('foo')

@cli.command()
def bar():
    click.echo('bar')

Then you can invoke that without explicit subcommand name:

$ cli.py --help
Usage: cli.py [OPTIONS] COMMAND [ARGS]...

Options:
  --help    Show this message and exit.

Command:
  foo*
  bar

$ cli.py
foo
$ cli.py foo
foo
$ cli.py bar
bar

Compatibility

click-default-group is compatible with these Click versions:

  • Click-8.x
  • Click-7.x
  • Click-6.x
  • Click-5.x
  • Click-4.x

Licensing

Written by Heungsub Lee, and distributed under the BSD 3-Clause license.