Skip to content

fix: complete subcommand flags after positional arguments - #2426

Merged
dearchap merged 1 commit into
urfave:mainfrom
fzlzjerry:fix/2248-partial-flags-after-positional-args
Sep 14, 2026
Merged

dearchap merged 1 commit into
urfave:mainfrom
fzlzjerry:fix/2248-partial-flags-after-positional-args

Conversation

@fzlzjerry

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • bug

What this PR does / why we need it:

Fix the remaining partial-flag completion case after a positional argument in a child command. For example, current main completes app sub --pa, but app sub value --pa suggests child commands instead of matching flags.

DefaultCompleteWithFlags reads raw os.Args for the root command and parsed arguments for a child. Only the raw arguments still contain the trailing completion marker, so always selecting the penultimate argument skips the flag being completed in the child case.

  • help.go: start with the final argument and step back only when that argument is the completion marker.
  • completion_partial_regression_test.go: cover root, child, and nested commands with zero, one, and two positional arguments, plus hidden flags, custom-completer arguments, disabled completion, and requests after --.

The completion request format, flag parsing, and custom completion handlers are unchanged.

Which issue(s) this PR fixes:

Fixes #2248.

Testing

  • The completed regression suite fails for the four child/nested positional cases on unchanged 5081218 and passes with this change. The already-working root and no-positional cases stay unchanged.
  • Go 1.27.0: make all, make lint, make v3diff, and post-commit make diffcheck pass.
  • Go 1.26.5: make vet test check-binary-size passes.
  • Built the same CLI probe against the baseline and this branch and compared nine completion inputs. Matching flags replace the incorrect command suggestions; both binaries preserve ordinary action execution and produce no output/action for completion after --.

The README gfmrun target found zero executable blocks; the compiled CLI probe supplies the execution check above. macOS and Windows are left to CI.

Release Notes

Fix flag-name completion after positional arguments in subcommands and nested commands.

@fzlzjerry
fzlzjerry requested a review from a team as a code owner September 8, 2026 04:15
Copilot AI lite review requested due to automatic review settings September 8, 2026 04:15

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@dearchap dearchap left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

Approve. Small, targeted fix for the remaining partial-flag completion case after a positional argument in child/nested commands.

Verified locally

  • Confirmed the bug on base 50812189: new tests fail for all four child/nested positional cases (output suggests commands/help instead of flags).
  • Fix passes: TestPartialFlagCompletion* all green on head 816e14f1.
  • No regressions: full go test -count=1 ., go vet ./..., goimports -l all clean.

Minor non-blocking notes

  • TestPartialFlagCustomCompletionArgs asserts current behavior where cmd.Args() holds the partial --pa as positional — good to keep explicit.
  • No issues found with root-vs-child args asymmetry handling.

@fzlzjerry

Copy link
Copy Markdown
Contributor Author

Thanks, @dearchap, for the detailed review and the base/head regression check. I’ll keep the fix and the explicit custom-completion argument test as reviewed.

@dearchap
dearchap merged commit 7fc6782 into urfave:main Sep 14, 2026
9 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.

Auto-completion with unfinished partial flags (--XXX<TAB> returns no completions

3 participants