cli
cli copied to clipboard
How to implement something like an OptionFlag?
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.
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'}
?
@lynncyrin yes that is exactly what I meant.
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.
@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.
Ping @lynncyrin
This was previously requested in #620
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.
Not stale
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.
Here is how I implemented it using GenericFlag and a custom value
https://play.golang.org/p/BWBaQ0tTLKe
There is a PR for this feature. https://github.com/urfave/cli/pull/1234
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.
Wy Wy Wy! should we open it again?
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.
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.
This is a duplicate of #786 .