File: arguments.rst

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 (58 lines) | stat: -rw-r--r-- 1,787 bytes parent folder | download | duplicates (3)
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
50
51
52
53
54
55
56
57
58
Arguments with ``help``
=======================

If you've used Click before, you probably know that:

    ``click.argument()`` does not take a help parameter. This is to follow the
    general convention of Unix tools of using arguments for only the most
    necessary things, and to document them in the command help text by referring
    to them by name.

Cloup doesn't force the Unix convention on you. ``cloup.argument`` takes an
optional ``help`` parameter. If you pass a non-empty string to at least one of
the arguments of a command, Cloup will print a "Positional arguments" section
just below the command description.

.. tabbed:: Code
    :new-group:

    .. code-block:: python

        from pprint import pprint
        import cloup
        from cloup import option, option_group

        @cloup.command()
        @cloup.argument('input_path', help="Input path")
        @cloup.argument('out_path', help="Output path")
        @option_group(
            'An option group',
            option('-o', '--one', help='a 1st cool option'),
            option('-t', '--two', help='a 2nd cool option'),
            option('--three', help='a 3rd cool option'),
        )
        def main(**kwargs):
            """A test program for cloup."""
            pprint(kwargs, indent=3)

        main()

.. tabbed:: Generated help

    .. code-block:: none

        Usage: example [OPTIONS] INPUT_PATH OUT_PATH

          A test program for cloup.

        Positional arguments:
          INPUT_PATH      Input path
          OUT_PATH        Output path

        An option group:
          -o, --one TEXT  a 1st cool option
          -t, --two TEXT  a 2nd cool option
          --three TEXT    a 3rd cool option

        Other options:
          --help          Show this message and exit.