cli
cli copied to clipboard
Asking for the StringSlice value multiple times mutates it in some cases
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]
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.
Closing this as it has become stale.
Verified that issue does not exist in v1.22.10. Closing.