cli icon indicating copy to clipboard operation
cli copied to clipboard

Asking for the StringSlice value multiple times mutates it in some cases

Open tych0 opened this issue 5 years ago • 2 comments

my urfave/cli version is

v1.22.4

package main

import (
	"fmt"
	"os"

	"github.com/urfave/cli"
)

func doThing(ctx *cli.Context) error {
	fmt.Println("slice-arg:", ctx.StringSlice("slice-arg"))
	fmt.Println("slice-arg:", ctx.StringSlice("slice-arg"))
	fmt.Println("slice-arg:", ctx.StringSlice("slice-arg"))
	return nil
}

func main() {
	app := cli.NewApp()

	app.Commands = []cli.Command{
		cli.Command{
			Name:   "thing",
			Action: doThing,
			Flags: []cli.Flag{
				&cli.StringSliceFlag{
					Name: "slice-arg",
					Value: &cli.StringSlice{"a"},
				},
			},
		},
	}

	if err := app.Run(os.Args); err != nil {
		fmt.Fprintf(os.Stderr, "error: %+v\n", err)
		os.Exit(1)
	}
}
$ GO111MODULE=off go run tester.go thing --slice-arg b
slice-arg: [b]
slice-arg: [b b]
slice-arg: [b b]
$ GO111MODULE=off go run tester.go thing --slice-arg b --slice-arg a
slice-arg: [b a]
slice-arg: [b a]
slice-arg: [b a]
$ GO111MODULE=off go run tester.go thing --slice-arg a --slice-arg b 
slice-arg: [a b]
slice-arg: [b b]
slice-arg: [b b b]

tych0 avatar Aug 05 '20 15:08 tych0

This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else.

stale[bot] avatar Nov 03 '20 15:11 stale[bot]

Closing this as it has become stale.

stale[bot] avatar Dec 03 '20 15:12 stale[bot]

Verified that issue does not exist in v1.22.10. Closing.

dearchap avatar Jan 10 '23 15:01 dearchap