command: apply SliceFlagSeparator to env-var values in PostParse#2313
Open
alliasgher wants to merge 3 commits intourfave:mainfrom
Open
command: apply SliceFlagSeparator to env-var values in PostParse#2313alliasgher wants to merge 3 commits intourfave:mainfrom
alliasgher wants to merge 3 commits intourfave:mainfrom
Conversation
When FlagStringer returns a string without a tab character, strings.Index returns -1 and out[-1:] panics with "slice bounds out of range [-1:]". Guard against this by clamping the index to 0 when no tab is found. In that case the entire FlagStringer output is used as the suffix portion of the formatted string, matching the intent of callers who use a custom stringer without the usual tab layout. Fixes urfave#2303 Signed-off-by: alliasgher <alliasgher123@gmail.com>
When HandleExitCoder received an ExitCoder whose Error() returned an
empty string (e.g. cli.Exit("", code)), it still called
fmt.Fprintln(ErrWriter, err) which wrote a bare newline to stderr.
Guard the print with a check on the error message so that an empty
message produces no output at all.
Fixes urfave#2263
Signed-off-by: alliasgher <alliasgher123@gmail.com>
setMultiValueParsingConfig was only called from cmd.set(), which is invoked when parsing command-line flags. When flag values came from an environment variable they were processed in flag.PostParse() which did not have the separator configured on the value, so the default "," separator was used regardless of the command's SliceFlagSeparator. Call setMultiValueParsingConfig for each flag in the PostParse loop so the separator is configured before any env-var lookup. Fixes urfave#2262 Signed-off-by: alliasgher <alliasgher123@gmail.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
SliceFlagSeparator(andDisableSliceFlagSeparator) were not applied to flag values sourced from environment variables.setMultiValueParsingConfig— which propagates the command's separator settings to the flag's underlying value — was only called insidecmd.set(). That path is taken when parsing CLI flags. When values come from environment variables they flow throughflag.PostParse(), which calledf.Set()without first configuring the separator. As a result the flag's value always used the default","separator regardless of whatSliceFlagSeparatorwas set to.Before
After
Fix
Add a
cmd.setMultiValueParsingConfig(flag)call in the PostParse loop (incommand_run.go) beforeflag.PostParse()so the separator is configured regardless of whether the value came from the CLI or an env var.Fixes #2262
Checklist
TestCommandSliceFlagSeparatorFromEnvVar)