CLI11 icon indicating copy to clipboard operation
CLI11 copied to clipboard

Enum help string formatting

Open tomazsustar opened this issue 4 years ago • 3 comments

I used the example code to be able to enter a parameter as a number or as enum string.

std::map<std::string, FirmwareUpdateBase::FirmwareUpdateFlags> flagsMap{
        { "normal", normal },                
        { "allow_downgrade", allow_downgrade },          
        { "force_update", force_update},            
        { "no_check", no_check},                 
        { "normal_check_only", normal_check_only},         
        { "allow_downgrade_check_only", allow_downgrade_check_only}, 
        { "force_update_check_only", force_update_check_only }
    };
    app.add_option("--flags", flags_, "FW Update Flags")->default_val(normal)->transform(CLI::CheckedTransformer(flagsMap));

However the formatting of the help string is not very clear. All values are displayed in one raw, which is than broken by the width console of the window and is hard to read.

Options:
 -h,--help                   Print this help message and exit
 --flags ENUM:value in {allow_downgrade->1,allow_downgrade_check_only->5,force_update->2,force_update_check_only->6,no_
check->3,normal->0,normal_check_only->4} OR {1,5,2,6,3,0,4}=0
                             FW Update Flags

Would it be possible to display enum options in separate lines? Something like below? This would make the help output much more useful.

Options:
 -h,--help                   Print this help message and exit
 --flags ENUM:value in {
       allow_downgrade->1,
       allow_downgrade_check_only->5,
       force_update->2,
       force_update_check_only->6,
       no_check->3,
       normal->0,
       normal_check_only->4
   } OR {1,5,2,6,3,0,4}=0
                               FW Update Flags

tomazsustar avatar Jan 26 '21 09:01 tomazsustar

I'd like something similar, though with the ability to format the integer parts in hex.

mikepyne avatar Apr 20 '21 17:04 mikepyne

I'd gladly just ditch the whole integer part. I have given those things a name for a reason and the integer values are just exposing implementation details that I bet someone will start relying on...

jzakrzewski avatar Jul 23 '21 14:07 jzakrzewski

I'd gladly just ditch the whole integer part.

just replace

CLI::Transformer(hashTypeMap, CLI::ignore_case)

with

CLI::Transformer(hashTypeMap, CLI::ignore_case)
   .description(CLI::detail::generate_map(CLI::detail::smart_deref(yourmap), true));

or any custom .description( generated out of your mapping

kvtb avatar Oct 02 '21 16:10 kvtb