Skip to content

Apply show_only_unused to arguments (fixes #125) - #137

Merged
auvipy merged 3 commits into
click-contrib:masterfrom
Sanjays2402:fix/show-only-unused-arguments
Sep 5, 2026
Merged

auvipy merged 3 commits into
click-contrib:masterfrom
Sanjays2402:fix/show-only-unused-arguments

Conversation

@Sanjays2402

Copy link
Copy Markdown
Contributor

Fixes #125

ClickCompleter(show_only_unused=True) only hid options that were already present on the line; click.Argument was never checked, so an argument kept being completed after a value had been supplied. _get_completion_for_cmd_args now skips an argument whose value is already bound in the completion context, mirroring the existing option handling; variadic arguments (nargs=-1) accept further values and are never hidden.

Regression tests were added to tests/test_completion/test_common_tests/test_arg_completion.py for both the plain and the variadic case; they fail on master and pass with the fix. Full suite: 69 passed, 5 skipped.

This change was prepared with AI assistance; the regression test was run locally and fails without the fix.

ClickCompleter(show_only_unused=True) only hid options that were already
present on the line; arguments were completed again even after a value had
been supplied.

_get_completion_for_cmd_args now skips a click.Argument whose value is
already bound in the completion context, mirroring the existing option
handling. Variadic arguments (nargs=-1) accept further values and are
never hidden.

Adds regression tests for both the plain and the variadic argument case.
@auvipy
auvipy requested review from auvipy and a lite review from Copilot September 5, 2026 07:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new argument “already used” detection relies on ctx.params, which can reflect defaults/envvars (not just command-line input) and may incorrectly hide argument completions under show_only_unused=True.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR fixes ClickCompleter(show_only_unused=True) so it also suppresses completions for click.Argument values that have already been provided, matching the existing behavior for click.Option, while keeping variadic arguments (nargs=-1) completable.

Changes:

  • Update _get_completion_for_cmd_args to skip completing an argument when it is already “used” (except variadic args).
  • Add regression tests covering both single-value and variadic arguments with show_only_unused.
  • Document the behavior change in Changelog.rst.
File summaries
File Description
click_repl/_completer.py Extends show_only_unused behavior to arguments during completion generation.
tests/test_completion/test_common_tests/test_arg_completion.py Adds regression tests for unused-argument hiding and the variadic exception.
Changelog.rst Notes the new show_only_unused behavior for arguments.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread click_repl/_completer.py
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The fallback argument detection can incorrectly hide completions for default or environment-derived values.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (1)

click_repl/_completer.py:284

  • Fixed-arity multi-value arguments are hidden before all their values have been entered. With nargs=2, parsing cmd foo records the source as COMMANDLINE, but resilient parsing leaves the argument value unbound because the second token is missing; this continue then suppresses the choices needed for that second value. Hide the argument only after its processed value is actually bound.
                if self.show_only_unused and already_present and param.nargs != -1:
                    continue
  • Files reviewed: 3/3 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread click_repl/_completer.py
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is narrowly scoped, aligns argument behavior with existing option handling, and includes targeted regression tests plus a changelog entry.

Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@auvipy
auvipy merged commit dc09e1b into click-contrib:master Sep 5, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

show_only_unused is not work for used Argument

3 participants