Cli: q: How to implement something like an OptionFlag?

Created on 19 Jun 2020  路  9Comments  路  Source: urfave/cli

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.

arev2 kinquestion statutriage

All 9 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

blackrez picture blackrez  路  5Comments

krostar picture krostar  路  5Comments

genieplus picture genieplus  路  5Comments

nkprince007 picture nkprince007  路  5Comments

l0k18 picture l0k18  路  3Comments