-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fixes urfave/cli#1648 #1649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes urfave/cli#1648 #1649
Conversation
@palsivertsen Thanks for the excellent PR. Do you think we should add an option whether to trim space or not ? |
No. Users can call |
This PR broke any code, including mine that was relying on strings to be trimmed by default. |
@skelouse @palsivertsen Can one of you submit a PR to include the option ? Thanks |
IMO the option should be NoTrimSpace or KeepSpaces v3 could be TrimSpace I'll leave it to @palsivertsen as he is relying on the default functionality to not trim. |
@palsivertsen Thanks for the quick response! Just reuse, it's still the same issue. Edit: I saw another place that was trimming spaces, may help with your use case. if val, source, found := flagFromEnvOrFile(f.EnvVars, f.FilePath); found {
for _, s := range f.separator.flagSplitMultiValues(val) {
if err := setValue.Set(strings.TrimSpace(s)); err != nil {
return fmt.Errorf("could not parse %q as string value from %s for flag %s: %s", val, source, f.Name, err)
}
}
// Set this to false so that we reset the slice if we then set values from
// flags that have already been set by the environment.
setValue.hasBeenSet = false
f.HasBeenSet = true
} |
@skelouse Thanks! Any idea where to put such a flag? My first instinct was to add it to the StringSliceFlag{Name: "slice", NoTrimSpace: true} But the |
@palsivertsen I had the same issue with v2, I'm not exactly sure how they are generated. Maybe someone else can provide input @urfave/cli on how to edit the generated structs for v2. |
@skelouse I figured out how to add the field to generated structs. Here's what I've got so far: |
Remove trim of whitespace in
StringSliceFlag
values, matching the behavior ofStringFlag
.What type of PR is this?
What this PR does / why we need it:
See #1648
Which issue(s) this PR fixes:
Fixes #1648
Special notes for your reviewer:
I'm uncertain if the trim behavior was intentional or not as there was no tests covering it.
Testing
Added test that verifies that parsing the same value using
StringFlag
andStringSliceFlag
results in equal values.Release Notes