Repository navigation
Conversation
|
The The change adds about 1.2KB (704 bytes of text and 527 of pclntab, measured with Go 1.27.3 for linux/amd64), but main is already close to the limit: it reports 2.2MB, and the check rounds to one decimal, so anything that crosses the next 4KB page reports 2.3MB. A version without the buffer lands on the same page, so I don't think trimming the code gets it back under. I can raise |
bc04167 to
bc36bb0
Compare
|
I've added a second commit that raises both limits by 0.1MB, as the check suggests, so CI can go green. The smallest size in CI ( |
bc36bb0 to
2127145
Compare
| // The root command completes os.Args, which still hold the flags, so a | ||
| // flag that needs nothing more must lead to the subcommands rather than | ||
| // to an empty list of flag suggestions. | ||
| origArgv := os.Args | ||
| t.Cleanup(func() { os.Args = origArgv }) |
The root command completes the arguments passed to Run, which still hold its flags, so after a flag that takes no value or has its value after "=", such as "app --verbose <TAB>", it printed flag suggestions for that flag and found none. A subcommand completes its parsed arguments and does not have this problem. Treat such a flag as complete unless it starts a longer flag name. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2127145 to
245af54
Compare
What type of PR is this?
What this PR does / why we need it:
The shell scripts send the word under the cursor only when it starts with
-, so forapp --verbose <TAB>the program getsapp --verbose --generate-shell-completion. A subcommand completes its parsed arguments, where--verbosehas already been consumed, soapp deploy --verbose <TAB>listsdeploy's subcommands. The root command completes its raw arguments instead, so its last argument is--verbose,DefaultCompleteWithFlagsprints flag suggestions for it, and sinceprintFlagSuggestionsskips the flag that was typed in full, it prints nothing. The same thing happens after a value given with=:DefaultCompleteWithFlagsnow treats the last argument as a complete flag, and lists the subcommands, when it names a flag that takes no value (including aBoolWithInverseFlag's--no-names) or has its value after=, and no longer flag starts with it. So--debugstill suggests--debug-level,--formatwith no value still prints nothing, and partial flags such as--verbwork as before. Subcommands do not reach the new branch for a known flag, since their parsed arguments no longer hold it.This is separate from #2489, which changes where the root command's arguments come from and not how the last one is read. It is rebased on #2489, so the new test passes its arguments to
Runinstead of settingos.Args.Which issue(s) this PR fixes:
None, found while testing the generated scripts in bash and fish.
Testing
TestCompletionAfterCompleteRootFlag: a bool flag, an inverse bool flag and--format=jsonlist the subcommands (these three fail onmain);--formatwith no value,--debugnext to--debug-level, and a partial--verbkeep their current output.app --verbose <TAB>,app --verbose d<TAB>andapp --config=x <TAB>now complete the subcommands. The other cases are unchanged.make(generate, vet, tests, binary size, gfmrun),make lintandmake v3diffpass.go test -racepasses, as do the tests withurfave_cli_no_template,urfave_cli_no_docsandurfave_cli_no_suggest.The change and the test were written with Claude Code (AI).
Release Notes
🤖 Generated with Claude Code