pallets / pallets/click

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

Open
#1,269 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

parsing
Dominant language
Python
Stars
17.7k
Forks
2.3k
Avg merge
1d 30m
Merged PRs (30d)
18

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the minimal Python reproduction from the issue with a chained Click command, both with and without the argument. Trace the chained-command argument parsing entry point and add or update the relevant regression coverage; done means an option after a command argument is recognized instead of reported as a command.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.