Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to implement something like an OptionFlag? #1154

Closed
marcofranssen opened this issue Jun 19, 2020 · 17 comments
Closed

How to implement something like an OptionFlag? #1154

marcofranssen opened this issue Jun 19, 2020 · 17 comments
Labels
area/v2 relates to / is being considered for v2 kind/question someone asking a question pinned should not be marked stale status/triage maintainers still need to look into this
Milestone

Comments

@marcofranssen
Copy link

How to implement something like an OptionFlag

I'm looking to implement a Flag which can have a few predefined values.

E.g.

mycli --output json
mycli --output xml

Is there a way to implement this using the existing flags while also informing the user of the cli what are the available options?

If not would it make sense to add this OptionFlag? I would be happy to make a PR for that with some guidance.

@marcofranssen marcofranssen added area/v2 relates to / is being considered for v2 kind/question someone asking a question status/triage maintainers still need to look into this labels Jun 19, 2020
@coilysiren
Copy link
Member

To rephrase the question - are if asking if there's a builtin way to implement a flag that gives users a set of choices from a predefined list? Something like Choices: []string{'json', 'xml'}?

@marcofranssen
Copy link
Author

@lynncyrin yes that is exactly what I meant.

@coilysiren
Copy link
Member

Makes sense! There's no obvious builtin way to implement this, but I've implemented a few "manual" versions of it. I don't happen to have that code on-hand, though.

@marcofranssen
Copy link
Author

@lynncyrin would be great if you could dig it up and share a snippet here with the community. I'm happy to take that snippet of your further to integrate it here.

@MarvinJWendt
Copy link

Ping @lynncyrin

@nielsvaneck
Copy link

This was previously requested in #620

@stale
Copy link

stale bot commented Dec 16, 2020

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 stale bot added the status/stale stale due to the age of it's last update label Dec 16, 2020
@MarvinJWendt
Copy link

Not stale

@stale
Copy link

stale bot commented Dec 16, 2020

This issue or PR has been bumped and is no longer marked as stale! Feel free to bump it again in the future, if it's still relevant.

@stale stale bot removed the status/stale stale due to the age of it's last update label Dec 16, 2020
@dearchap
Copy link
Contributor

dearchap commented Feb 6, 2021

Here is how I implemented it using GenericFlag and a custom value

https://play.golang.org/p/BWBaQ0tTLKe

@dearchap
Copy link
Contributor

dearchap commented Feb 8, 2021

There is a PR for this feature. #1234

@stale
Copy link

stale bot commented Jun 2, 2021

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 stale bot added the status/stale stale due to the age of it's last update label Jun 2, 2021
@stale
Copy link

stale bot commented Jul 4, 2021

Closing this as it has become stale.

@stale stale bot closed this as completed Jul 4, 2021
@abdennour
Copy link

Wy Wy Wy! should we open it again?

@dearchap
Copy link
Contributor

There are 2 ways to approach this. One is with PR #1234 . The other is using validations as in PR #1261 . Its upto the maintainers to choose the way forward.

@stale
Copy link

stale bot commented Jul 25, 2021

This issue or PR has been bumped and is no longer marked as stale! Feel free to bump it again in the future, if it's still relevant.

@stale stale bot removed the status/stale stale due to the age of it's last update label Jul 25, 2021
@meatballhat meatballhat changed the title q: How to implement something like an OptionFlag? How to implement something like an OptionFlag? Apr 21, 2022
@meatballhat meatballhat added this to the Release 2.5.0 milestone Apr 21, 2022
@dearchap
Copy link
Contributor

This is a duplicate of #786 .

@dearchap dearchap closed this as not planned Won't fix, can't repro, duplicate, stale Oct 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/v2 relates to / is being considered for v2 kind/question someone asking a question pinned should not be marked stale status/triage maintainers still need to look into this
Projects
None yet
Development

No branches or pull requests

8 participants