Display possible value for enum in Help text
See original GitHub issueI have several options for my command which are limited to enumerated types. Currently, the help text is displayed as follows:
Usage: ghi list [options]
Options:
-?|-h|--help Show help information
-a|--all All
-r|--repo <REPOSITORY> The repository to limit the issues to
-u|--user <USER> The user who the issues are related to
-R|--rel <RELATION> The relation of the issues to the user
-s|--state <STATE> The state of the issues
-t|--token <TOKEN> Your GitHub Personal Access token
But I want to display the possible values for the enumerated types. What I have done (for now) is to update the rel
option, for example, as follows:
[Option(CommandOptionType.SingleValue, Description = "The relation of the issues to the user", ShortName = "R", LongName = "rel",
ValueName = "Assigned|Created|Mentioned")]
public IssueRelation Relation { get; set; } = IssueRelation.Assigned;
This will then display the possible values as follows:
Usage: ghi list [options]
Options:
-?|-h|--help Show help information
-a|--all All
-r|--repo <REPOSITORY> The repository to limit the issues to
-u|--user <USER> The user who the issues are related to
-R|--rel <Assigned|Created|Mentioned> The relation of the issues to the user
-s|--state <STATE> The state of the issues
-t|--token <TOKEN> Your GitHub Personal Access token
Is this the correct way to go about it? Or is there a way to automatically display the list of values in the case of enumerated types which I have missed?
Also, is this not perhaps something we can add as a standard “feature” to the generated help text? I think it is pretty common for certain options to be limited to specific predefined values.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:13 (11 by maintainers)
Top Results From Across the Web
How to show enum values in help text · Issue #643
I think this is trivial, but I haven't found an easy way to include the enum values in the help text.
Read more >c# - Display Text for Enum
Yes. It's giving you an error because your code is wrong. You can't make "B+" an enum value because there's a plus sign....
Read more >Attaching Values to Java Enum
Locating Java Enum Values. Java provides a valueOf(String) method for all enum types. Thus, we can always get an enum value based on...
Read more >Enumeration format strings
Displays the enumeration entry as a string value, if possible, and otherwise displays the integer value of the current instance.
Read more >Enums
You can use the enum keyword to specify possible values of a request parameter or a model property. For example, the sort parameter...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve had similar requests, so not going to close. I think its a useful feature; I just haven’t thought thru an API for it.
Whatever API we come up with needs to be flexible enough to allow users to control the output. I don’t want to add behavior that is hard to override or change. While some may like the int<->Enum mapping, I know others who would not.