Repository navigation
Conversation
A "--" ends flag parsing, and every argument after it is an argument of the command. The first of them was still looked up as a subcommand name, so "app -- cmd --x" ran the cmd subcommand, which then parsed --x as a flag.
This branch has not been deployed
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.
What type of PR is this?
What this PR does / why we need it:
A
--ends flag parsing, and everything after it should be an argument of the command. That works for flags, but the first argument after--is still looked up as a subcommand name:On
main,app -- subprintssub ran, andapp -- sub --xfails withflag provided but not defined: -x, becausesubthen parses--xas a flag. Expected: the root action runs withargs: [sub]andargs: [sub --x]. Shell completion already follows this rule: since #2412 it suggests nothing after a--, "only positional arguments are accepted after it", soapp -- su<TAB>offers nothing butapp -- subruns the subcommand.command_parse.go:parseFlagsrecords when the parsed args start right after a--(nothing positional came before it).command_run.go: in that case the first arg is not looked up as a subcommand (or passed toSuggestCommandFunc).DefaultCommandstill applies, soapp -- foobehaves likeapp foodid before.command.go: the unexported field that holds this state.command_test.go:TestCommand_CommandNameAfterTerminatorIsAnArgument.A
--that comes after a positional argument (app foo -- sub) already worked, sincefoowas taken as the first argument.Which issue(s) this PR fixes:
None, found while checking
--handling with subcommands.Testing
TestCommand_CommandNameAfterTerminatorIsAnArgumentfails onmainwithflag provided but not defined: -notAFlagandthe subcommand must not run when its name follows "--", and passes with this change.make vet,make test,make test GFLAGS='--tags urfave_cli_no_template',make lint,make check-binary-size,make generate,make diffcheckandmake v3diffpass, andgolangci-lint runreports 0 issues.Release Notes