Skip to content

Using Destination with StringSliceFlags break DisableSliceFlagSeparator and SliceFlagSeperator controls #2069

@dereknola

Description

@dereknola

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/v2relates to / is being considered for v2kind/bugdescribes or fixes a bugstatus/triagemaintainers still need to look into this

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions