pallets / pallets/click

Context.params isn't setup in the MultiCommand.list_commands method

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

Expected Behavior

I can refer parsed options in MultiCommand.list_commands method.

Actual Behavior

I can't. Options aren't initialized in the list_commands.

I'm creating a CLI tool that dynamically loads subcommands from a file. And the location of the file is specified by an option of the CLI tool. I can refer the parsed option in MultiCommand.get_command but I can't refer it in MultiCommand.list_commands method.

I think the list_command method is called before finishing the parse_args method so we can't use parsed options in the list_commands.

https://github.com/pallets/click/blob/fef921a4d0c807673d7800af4dd4ca604f6489e4/src/click/core.py#L1242
https://github.com/pallets/click/blob/fef921a4d0c807673d7800af4dd4ca604f6489e4/src/click/core.py#L1217

I created the following file and I got an empty dictionary object by the logger.debug when I execute the following command.

https://github.com/polikeiji/bkm/blob/master/bkm.py#L94

python -m bkm -f AAA --help

Is this behavior the expected one?

Environment
  • Python version: 3.8.0
  • Click version: 7.1.2

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

Reproduce the reported behavior with python -m bkm -f AAA --help, then inspect src/click/core.py around MultiCommand.list_commands, get_command, and parse_args, along with the referenced bkm.py. Determine whether parsed options should be available during command listing, and consider the issue complete when the documented behavior is resolved and verified against this reproduction.

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
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.