Skip to content

Add optional check for duplicated string and int type flags. #1071

Description

@arykalin

Checklist

  • [y] Are you running the latest v2 release? The list of releases is here.
  • [y] Did you check the manual for your release? The v2 manual is here
  • [y] Did you perform a search about this feature? Here's the Github guide about searching.

What problem does this solve?

Sometimes users can accidently duplicate string type flags and then the latest value we be taken. It is not clear and bad for usability.

Solution description

Add an option called Duplicated true\false to flag options. Example:

flagFoo = &cli.StringFlag{
	Name: "foo",
	Duplicated: false,
}

A detailed description of what you want to happen.

if Duplicated set to false command should fail with error
"flag foo can not be duplicated"

Describe alternatives you've considered

For now, as a workaround, we're using StringSliceType for flags we don't want to be duplicated and check that slice have only one element in it.

https://github.com/Venafi/vcert/blob/8e1dc13c0afdd615d7f27b80190ddf3a1d07e848/cmd/vcert/commands.go#L105-L120

Activity

  1. added
    area/v2
    status/triage
    on Feb 14, 2020
  2. coilysiren commented on Feb 26, 2020

    @coilysiren
    Member

    Sometimes users can accidently duplicate string type flags and then the latest value we be taken. It is not clear and bad for usability.

    Oh wow that sucks 😅we should definitely fix this 👍although possibly only in v3? Because I'm not sure if it would be considered a "breaking change"

  3. added
    help wanted
    status/confirmed
    and removed
    status/triage
    on Feb 26, 2020
  4. stale commented on May 26, 2020

    @stale

    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.

  5. added
    status/stale
    on May 26, 2020
  6. stale commented on Jun 25, 2020

    @stale

    Closing this as it has become stale.

  7. removed
    status/stale
    on Apr 22, 2022
  8. changed the title [-]v2 feature: Add optional check for duplicated string and int type flags.[/-] [+]Add optional check for duplicated string and int type flags.[/+] on Apr 22, 2022
  9. added
    area/v3
    and removed
    area/v2
    on Oct 17, 2022
  10. dearchap commented on Oct 21, 2022

    @dearchap
    Contributor

    Will consider for v3

  11. dearchap commented on Nov 28, 2022

    @dearchap
    Contributor

    @arykalin If I understand correctly you've defined 2 flags(same type) with same name and only the last defined one will pick up values ?

  12. dearchap commented on Dec 1, 2022

    @dearchap
    Contributor

    @arykalin Looking at your code you've defined "instance" as a stringslice flag and then enforced that if should not be length > 1 . Is this because if you've defined instance as a string flag and then people use the flag twice like --instance id1 and --instance id2 and then only the last value is taken. That is what you would like to guard against. ?

  13. added
    status/claimed
    on Dec 18, 2022
  14. self-assigned this
    on Dec 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/v3help wantedstatus/claimedstatus/confirmed

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions