File: flat_option_groups.py

package info (click to toggle)
python-cloup 3.0.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 936 kB
  • sloc: python: 5,371; makefile: 120
file content (40 lines) | stat: -rw-r--r-- 1,131 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
"""
Example of option groups, "flat style".
"""
import click

import cloup
from cloup import OptionGroup, option
from cloup.constraints import If, RequireAtLeast, mutually_exclusive

_input = OptionGroup(
    'Input options',
    help='This is a very useful description of the group',
    constraint=mutually_exclusive,
)
_output = OptionGroup(
    'Output options',
    constraint=If('three', then=RequireAtLeast(1)),
)


@cloup.command('cloup_flat', align_option_groups=True, no_args_is_help=True)
# Input options
@_input.option('-o', '--one', help='1st input option')
@_input.option('--two', help='2nd input option')
@_input.option('--three', help='3rd input option')
# Output options
@_output.option('--four', help='1st output option')
@_output.option('--five', help='2nd output option')
@_output.option('--six', help='3rd output option')
# Other options
@option('--seven', help='first uncategorized option',
        type=click.Choice('yes no ask'.split()))
@option('--height', help='second uncategorized option')
def main(**kwargs):
    """A CLI that does nothing."""
    print(kwargs)


if __name__ == '__main__':
    main()