The Wayback Machine - https://web.archive.org/web/20210204190348/https://github.com/pallets/click/issues/1269
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chained command with argument and option results in "No such command" #1269

Open
lemon24 opened this issue Mar 31, 2019 · 3 comments
Open

Chained command with argument and option results in "No such command" #1269

lemon24 opened this issue Mar 31, 2019 · 3 comments
Labels
Milestone

Comments

@lemon24
Copy link

@lemon24 lemon24 commented Mar 31, 2019

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):

import click

@click.group(chain=True, no_args_is_help=False)
def cli():
    pass

@cli.command()
@click.argument('argument')
@click.option('--option')
def command(argument, option):
    pass

if __name__ == '__main__':
    cli()

Results in:

$ 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.
@lemon24 lemon24 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." Mar 31, 2019
@lemon24 lemon24 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" Mar 31, 2019
@lemon24
Copy link
Author

@lemon24 lemon24 commented 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.

@jcrotts
Copy link
Member

@jcrotts jcrotts commented 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
Copy link
Member

@jcrotts jcrotts commented May 28, 2019

@jab jab added the save-for-sprint label May 30, 2019
@davidism davidism added f:chain and removed save-for-sprint labels Jun 16, 2020
@davidism davidism added this to the 9.0.0 milestone Aug 13, 2020
@davidism davidism removed the docs label Aug 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants