Skip to content
Myr

Add docs about strict separation of parameters

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This addresses a question raised in #161 and is also kind-of related to #108. The new section could also have been added to /parameters/, but i feel it is more relevant here for users who are starting to learn about subcommands. The behavior is totally irrelevant when writing a program without subcommands, however sophisticated the usage of options and arguments might be.

authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parent 5ce9e40 · Browse files · 1 file+20 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+20 added−0 removed

  • other:+20 added−0 removed

1 file+20 added−0 removed

modified:docs/commands.rst+20 added
37 unmodified lines
38 invoke(cli, prog_name='tool.py')39 println()40 invoke(cli, prog_name='tool.py', args=['--debug', 'sync'])4142Passing Parameters43------------------4445Click strictly separates parameters between commands and subcommands. What this46means is that options and arguments for a specific command have to be specified47*after* the command name itself, but *before* any other command names.4849This behavior is already observable with the predefined ``--help`` option.50Suppose we have a program called ``tool.py``, containing a subcommand called51``sub``.5253- ``tool.py --help`` will return the help for the whole program (listing54 subcommands).5556- ``tool.py sub --help`` will return the help for the ``sub`` subcommand.5758- But ``tool.py --help sub`` will treat ``--help`` as an argument for the main59 program. Click then invokes the callback for ``--help``, which prints the60 help and aborts the program before click can process the subcommand.6162Nested Handling and Contexts63----------------------------6465As you can see from the earlier example, the basic command group accepts a
297 unmodified lines