Skip to content

cli.StringSliceFlag and default value #160

Closed

Description

@vieux

Hello,
I define my flag as follow:

flFilter = cli.StringSliceFlag{
        Name:  "filter",
        Value: &cli.StringSlice{"flag1", "flag2", "flag3"},
}

If I start my binary without arguments, c.StringSlice("filter") returns ["flag1", "flag2", "flag3"] as expected.
If I start my binary with --filter flag4, c.StringSlice("filter") returns ["flag1", "flag2", "flag3", "flag4"]. I find this behaviour odd, I expected it to erase the default value.
Even worst, if I start my binary with --filter flag1, c.StringSlice("filter") returns ["flag1", "flag2", "flag3", "flag1"].

Is this the expected behavior ? I know I have 3 default value so I can do c.StringSlice("filter")[3:] if set, but still it's not perfect.

Activity

  1. jszwedko commented on Jan 8, 2015

    @jszwedko
    Contributor

    Mmm this definitely feels unexpected to me.

  2. icexin commented on Dec 10, 2015

    @icexin

    EnvVar of StringSlice also has this behavior.

  3. huguesalary commented on Mar 8, 2016

    @huguesalary

    I also have this issue and also feels this behavior is completely unexpected. Is there any plans on fixing this?

    I'll see if I can take a stab at it and do a PR too.

  4. added
    kind/bug
    on Mar 8, 2016
  5. self-assigned this
    on Mar 8, 2016
  6. jszwedko commented on Mar 20, 2016

    @jszwedko
    Contributor

    I'd be happy to review a PR for this @huguesalary !

  7. jinhao commented on Mar 23, 2016

    @jinhao

    I also hava this issue, expect to change this behavior.

  8. added a commit that references this issue on Apr 5, 2016
    867aa09
  9. added
    status/claimed
    on Apr 5, 2016
  10. jszwedko commented on May 21, 2016

    @jszwedko
    Contributor

    Fixed by #392 (will be released is v2, but you can use that branch for now).

  11. removed
    status/claimed
    on May 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions