Skip to content
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

Using Destination with StringSliceFlags break DisableSliceFlagSeparator and SliceFlagSeperator controls #2069

Open
3 tasks done
dereknola opened this issue Mar 4, 2025 · 0 comments
Labels
area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/triage maintainers still need to look into this

Comments

@dereknola
Copy link

My urfave/cli version is

v2.27.5

Checklist

  • Are you running the latest v2 release? The list of releases is here.
  • Did you check the manual for your release? The v2 manual is here
  • Did you perform a search about this problem? Here's the GitHub guide about searching.

Dependency Management

  • My project is using go modules.

Describe the bug

I've tracked this down to how the flags are defined. Specifically, if a StringSliceFlag is given a Destination to store the StringSlice, the settings for flag seperators are not carried over when processing this Slice.

To reproduce

I've created a simple golang program to replicate this issue.

CODE

package main

import (
	"fmt"
	"os"

	"github.com/urfave/cli/v2"
)

var aaStorage cli.StringSlice

func main() {
	app := &cli.App{
		DisableSliceFlagSeparator: true,
		Commands: []*cli.Command{
			{
				Name: "runner",
				Flags: []cli.Flag{
					&cli.StringSliceFlag{
						Name:        "aa",
						Usage:       "Multi string with Destination",
						Destination: &aaStorage,
					},
					&cli.StringSliceFlag{
						Name:  "bb",
						Usage: "Multi string default",
					},
				},
				Action: func(c *cli.Context) error {
					fmt.Println("aa raw:", aaStorage)
					fmt.Println("aa value:", aaStorage.Value())
					bbStorage := c.StringSlice("bb")
					fmt.Println("bb raw:", bbStorage)
					return nil
				},
			},
		},
	}

	err := app.Run(os.Args)
	if err != nil {
		fmt.Println(err)
	}
}

Describe the steps or code required to reproduce the behavior

Observed behavior

Running above code with

./main runner --aa="11,22" --aa="33" --bb="44,55" --bb="66"

Produces

aa raw: {[11 22 33] { false false} true false}
aa value: [11 22 33]
bb raw: [44,55 66]

What did you see happen immediately after the reproduction steps
above?

Expected behavior

DisableSliceFlagSeparator is respected on all Destination values

Additional context

I work on k3s and we are attempting to migrate from v1 to v2. During this process, we have had difficulty with the changes around StringSliceFlag. Specifically issues with using the DisableSliceFlagSeparator option, as we pass flag values that contain , into embedded collectables.
Add any other context about the problem here.

If the issue relates to a specific open source GitHub repo, please
link that repo here.

If you can reproduce this issue with a public CI system, please
link a failing build here.

Want to fix this yourself?

Not sure where to start.

We'd love to have more contributors on this project! If the fix for
this bug is easily explained and very small, feel free to create a
pull request for it.

Run go version and paste its output here

# paste `go version` output in here

Run go env and paste its output here

# paste `go env` output in here
@dereknola dereknola added area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/triage maintainers still need to look into this labels Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/v2 relates to / is being considered for v2 kind/bug describes or fixes a bug status/triage maintainers still need to look into this
Projects
None yet
Development

No branches or pull requests

1 participant