question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Display possible value for enum in Help text

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
natemcmastercommented, Apr 25, 2018

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.

1reaction
natemcmastercommented, Apr 26, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found