Cli: StringSlice question

Created on 11 Oct 2019  Â·  7Comments  Â·  Source: urfave/cli

Hi

This is more of a question than an issue, but I was curious.

So if you have a StringSlice flag, say f1, then the expected behaviour from my side would be:

-f a b c -> []string{"a", "b", "c"}

However, the result is:
-f a b c -> []string{"a"}
and b and c is simply ignored.

It does work if you quote the strings though:
-f "a b c -> []string{"a", "b", "c"}

Is this expected behaviour?

cli version: b67dcf995b6a7b7f14fad5fcb7cc5441b05e814b (1.19.1)

kinquestion statuuser-feedback-required

Most helpful comment

It should be used like: --test a --test b --test c

All 7 comments

@oleorhagen can you test this in 1.22.1? I want to try and avoid spending time debugging behavior that may not exist anymore.

I am getting the same results:

```➜ testground ./testground -test a b c
[a]
➜ testground ./testground -test "a b c"
[a b c]


Using:

package main

import (
"fmt"
"log"
"os"

"github.com/urfave/cli"

)

func main() {

app := cli.NewApp()

app.Flags = []cli.Flag{
    cli.StringSliceFlag{
        Name:  "test",
        Usage: "Testing flags",
    },
}

app.Action = func(c *cli.Context) error {
    fmt.Println(c.StringSlice("test"))
    return nil
}

err := app.Run(os.Args)
if err != nil {
    log.Fatal(err)
}

}

```

Sry, private account. Anywho. This is using latest

It should be used like: --test a --test b --test c

Alright, I understand not an issue. Slightly unexpected though.

Still, closing.

Thx everyone.

If @lynncyrin thinks this is a real issue feel free to keep it open, I'm not a maintainer of this lib. I just built multiple apps and gathered that knowledge though that :)

I prefer to close issues in general ^_^ thanks for helping out @tboerger!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LeonB picture LeonB  Â·  5Comments

errashe picture errashe  Â·  3Comments

genieplus picture genieplus  Â·  5Comments

l0k18 picture l0k18  Â·  3Comments

krostar picture krostar  Â·  5Comments