You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Chained command with argument and option results in "No such command" #1269
Chained command with argument and option results in "No such command"; according to the documentation,
Other than that [nargs=-1 being allowed only on the last chained command] there are no restrictions on how they [chained commands] work. They can accept options and arguments as normal.
Reproduced on Ubuntu 18.04 with Python 3.5, 3.6 and 3.7, for all tagged Click versions between 3.0 and 7.0 (chain= does not seem to be supported for the ones before that).
Minimal repro (removing the argument allows the option to be recognized):
$ python3 test.py command a --option x
Usage: test.py [OPTIONS] COMMAND1 [ARGS]... [COMMAND2 [ARGS]...]...
Try "test.py --help" for help.
Error: No such command "--option".
$ python3 test.py command --help
Usage: test.py command [OPTIONS] ARGUMENT
Options:
--option TEXT
--help Show this message and exit.
changed the title [-]Chained command with argument and option results in "Error: Missing command.[/-][+]Chained command with argument and option results in "Error: Missing command."[/+]on Mar 31, 2019
changed the title [-]Chained command with argument and option results in "Error: Missing command."[/-][+]Chained command with argument and option results in "No such command"[/+]on Mar 31, 2019
OK, looking at the OptionParser instances used in the example above, I saw that they have allow_interspersed_args set to False (used to "to implement nested subcommands safely", which makes sense).
This, however, leads to inconsistent behavior:
non-chained commands allow both the --option argument and the argument --option orders
chained commands only allows --option argument
While the help text clearly states that commands should be called like [OPTIONS] ARGUMENT, the fact that both orders work in most of the cases may be confusing to users (it was for me, at least).
If I understand correctly, it's unlikely argument --option will ever be possible for chained commands. Should I update the Multi Command Chaining section to reflect the behavior described above? Why not Argparse? implies it, but that's not the first place someone would look when encountering it.
Seems reasonable to add a line in the docs to say that you have to use argument followed by options. Although I recall this being mentioned several places in the docs.
Activity
[-]Chained command with argument and option results in "Error: Missing command.[/-][+]Chained command with argument and option results in "Error: Missing command."[/+][-]Chained command with argument and option results in "Error: Missing command."[/-][+]Chained command with argument and option results in "No such command"[/+]lemon24 commentedon Mar 31, 2019
OK, looking at the OptionParser instances used in the example above, I saw that they have allow_interspersed_args set to False (used to "to implement nested subcommands safely", which makes sense).
This, however, leads to inconsistent behavior:
--option argumentand theargument --optionorders--option argumentWhile the help text clearly states that commands should be called like
[OPTIONS] ARGUMENT, the fact that both orders work in most of the cases may be confusing to users (it was for me, at least).If I understand correctly, it's unlikely
argument --optionwill ever be possible for chained commands. Should I update the Multi Command Chaining section to reflect the behavior described above? Why not Argparse? implies it, but that's not the first place someone would look when encountering it.jcrotts commentedon May 6, 2019
Seems reasonable to add a line in the docs to say that you have to use argument followed by options. Although I recall this being mentioned several places in the docs.
jcrotts commentedon May 28, 2019
#1323