pallets / pallets/click

Subcommands prefixed with a forward slash are seemingly ignored

Open
#1,322 1 comment 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

I don't actually have any clue what's going on here, but I've tracked the misbehavior down to a specific commit, with a failing test fails on this commit, but succeeds on the previous commit.

Let's start with the test case:

def test_bad_command(runner):
    @click.group()
    def cli():
        pass

    @cli.command()
    def wups():
        pass

    result = runner.invoke(cli, ['other'])
    assert 'No such command' in result.output

    result = runner.invoke(cli, ['/other'])
    assert 'No such command' in result.output

This probably explains the issue better. In normal situations, we'd expect some call to cli other to come back and error with "No such command ...", but in the case if prefixing with a forward slash, it somehow tricks the parser into ignoring the entire argument and instead, we get the help of the parent command.

This behavior seems to be broken starting with commit 0a2919f34fcbc635d8530b4c5b60bf119b2bcedb, and the tests fail when applied here, but pass when applied against e68766c35ab134af2db2abf7cbd6f31e9b25d150.

Let me know if there's more information I can provide to help find the issue.

To add to it, in terms of releases, this means the behavior worked against Click 5.1, but has failed since Click 6.0 and continues to not work through latest master.

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

Start by reproducing the provided test_bad_command case with Click's CLI runner, comparing behavior around commits 0a2919f34fcbc635d8530b4c5b60bf119b2bcedb and e68766c35ab134af2db2abf7cbd6f31e9b25d150. Trace how the CLI parser handles the /other argument. Done means both other and /other produce a No such command error instead of showing the parent command's help.

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
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.