fix: ignore non-command args after help flag#2382
Open
happysnaker wants to merge 2 commits into
Open
Conversation
Signed-off-by: Shirong Lu <73147033+happysnaker@users.noreply.github.com>
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--help/-hflag unless they resolve to an actual child commandhelp <command>behavior unchangedProblem
Issue #2126 reports that
--helpcurrently breaks when a command also has positional arguments. For example,command ciao --helpends up trying to resolveciaoas a help topic and returnsNo help topic for 'ciao'instead of showing the command help.The root cause is that
helpCommandActioncannot distinguish between:helpsubcommand (app help foo), where a following token should still be treated as a help topic, andapp foo --help ciao/app foo ciao --help), where extra positional args should be ignored unless they are an actual child command.Fix
--help/-hpath in the execution context before dispatching intohelpCommandActionhelpCommandAction, only treat the first positional token as a help topic when:helpsubcommand was invoked, orThis keeps existing explicit
help <command>behavior intact while making the flag path match the expectation from #2126.Testing
myCLI --help ciaomyCLI command ciao --helpmyCLI command --help ciaoI did not wait for a full local
go test ./...run to complete in this environment, so CI should be treated as the verification source of truth for the full suite.Fixes #2126