Skip to content

command: apply SliceFlagSeparator to env-var values in PostParse#2313

Open
alliasgher wants to merge 1 commit intourfave:mainfrom
alliasgher:fix-slice-separator-env-var
Open

command: apply SliceFlagSeparator to env-var values in PostParse#2313
alliasgher wants to merge 1 commit intourfave:mainfrom
alliasgher:fix-slice-separator-env-var

Conversation

@alliasgher
Copy link
Copy Markdown
Contributor

Summary

SliceFlagSeparator (and DisableSliceFlagSeparator) 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 inside cmd.set(). That path is taken when parsing CLI flags. When values come from environment variables they flow through flag.PostParse(), which called f.Set() without first configuring the separator. As a result the flag's value always used the default "," separator regardless of what SliceFlagSeparator was set to.

Before

export A="a;b;c"
./myapp  # SliceFlagSeparator: ";"
# cmd.StringSlice("a") → ["a;b;c"]  ← NOT split

After

export A="a;b;c"
./myapp  # SliceFlagSeparator: ";"
# cmd.StringSlice("a") → ["a", "b", "c"]  ← correctly split

Fix

Add a cmd.setMultiValueParsingConfig(flag) call in the PostParse loop (in command_run.go) before flag.PostParse() so the separator is configured regardless of whether the value came from the CLI or an env var.

Fixes #2262

Checklist

  • Test added (TestCommandSliceFlagSeparatorFromEnvVar)
  • Full test suite passes

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>
@alliasgher alliasgher force-pushed the fix-slice-separator-env-var branch from 54b0033 to 0ff1088 Compare April 15, 2026 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Split separator in StringSliceFlag ignored when using environment variable as source

2 participants