Repository navigation
fix: preserve incomplete short groups for shell completion - #2485
Conversation
Authored with Codex. Keep pending grouped tokens available to custom completion callbacks, matching the existing single-flag behavior. Signed-off-by: Eng Zer Jun <[email protected]>
5dbdb10 to
f529377
Compare
Juneezee
left a comment
There was a problem hiding this comment.
Thanks! This also fixes the default completer on a subcommand: with a bool flag all aliased a, app sub -al<TAB> used to suggest subcommands and now suggests --all.
I rebased onto main and pushed two changes:
- Completion now also keeps a group whose value-taking flag is not last, such as
-ba. Before this, with flagsa(bool),b(string) andbatch(bool),app sub -ba<TAB>suggested subcommands instead of--batch, and a custom callback got[]:
Lines 275 to 284 in f529377
- I replaced
completion_short_group_test.gowith four cases in the existing completion test. Most of the old file re-tested normal group parsing that other tests already cover:
Lines 603 to 617 in f529377
I also updated the PR description to match.
|
Thanks for catching the non-final value-taking case and consolidating the tests. I verified |
What type of PR is this?
What this PR does / why we need it:
With
UseShortOptionHandlingenabled, custom shell completion loses an unfinished grouped flag fromcmd.Args(). For example, declare booleanaand stringb, then run:A
ShellCompletecallback readingcmd.Args().Slice()currently receives only["value"]. After this change it receives["value", "-ab"], matching the existing handling of an unfinished single flag such as-b.command_parse.goretains the unparsed tail during shell completion when a short group contains an unknown flag, has a value-taking flag that is not last (-ba), or its final value-taking flag has no value yet. Normal invocations still return their original errors. Complete groups, including an explicit empty value (-ab=), remain consumed normally.TestCommand_Run_CustomShellCompleteAcceptsMalformedFlagscovers each of these groups, and a complete group that is still consumed during completion.Which issue(s) this PR fixes:
Independently reproduced on main
10f69fd3c38de86a3bc17810dcb7f818b494f027; no existing matching issue or open PR found in the search before submission.Special notes for your reviewer:
Authored and tested with a Codex agent on behalf of kimjooyoon. This change adds no dependency and changes no public API. It extends the existing single-flag completion behavior to grouped short flags.
Testing
Rebased onto main
63c2771c704accdd5f07eb40006c918da9687372:-an,-axand-nacases fail on main and pass with the fix.go test ./...,go test -tags urfave_cli_no_template ./...,go test -race ./...,go vet ./...and golangci-lint pass.Release Notes