File: multi_commands.py

package info (click to toggle)
click-help-colors 0.9.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 156 kB
  • sloc: python: 716; makefile: 4
file content (49 lines) | stat: -rw-r--r-- 813 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import click
from click_help_colors import HelpColorsGroup, HelpColorsMultiCommand


@click.group()
def cmd1():
    pass


@cmd1.command()
@click.option('--count', default=1, help='Some number.')
def command1(count):
    click.echo('command 1')


@click.group(
    cls=HelpColorsGroup,
    help_headers_color='red',
    help_options_color='blue'
)
def cmd2():
    pass


@cmd2.command()
@click.option('--name', help='Some string.')
def command2(name):
    click.echo('command 2')


class MyCLI(HelpColorsMultiCommand):
    def list_commands(self, ctx):
        return ['cmd1', 'cmd2']

    def get_command(self, ctx, name):
        return globals()[name]


@click.command(
    cls=MyCLI,
    help_headers_color='yellow',
    help_options_color='green'
)
def cli():
    pass


if __name__ == '__main__':
    cli()