BradleyChatha / jcli

A CLI framework for D
MIT License
23 stars 4 forks source link

Allow enum values to be given specific names and descriptions #9

Open BradleyChatha opened 4 years ago

BradleyChatha commented 4 years ago

_Originally posted by @andrey-zherikov in https://github.com/BradleyChatha/jcli/pull/5#discussion_r517252918:_

Here you might want to allow @Description UDA that will be used in help text:

enum {
    @Description("Even returns 1. Odd returns 0.")
    normal,
    @Description("Even returns 0. Odd returns 1.")
    reversed
}

Thinking about this more, sometimes certain enum values should not be exposed to CLI caller and so shouldn't be printed on help screen. From the other side enum value might not be equal to CLI argument value, so here might be a better approach:

enum {
    @CommandArgValue("normal", "Even returns 1. Odd returns 0.")
    normal_mode,
    @CommandArgValue("reversed", "Even returns 0. Odd returns 1.")
    reverse_mode,

    some_reserved_mode,  // internal value that is not exposed to CLI
}

While I do like the idea, here's some points I need sorting out:

While a case like this will definitely happen, what should we do by default? If an enum has no @CommandArgValue members then do we provide the current behaviour, or do we force the user to provide @CommandArgValue every time for every enum for every enum value they want?

Any ideas or existing examples of how to format the help text to display this information?

BradleyChatha commented 4 years ago

Just saw https://github.com/BradleyChatha/jcli/pull/5#discussion_r517267947 which gives me a start on how the help text should look.