fsprojects / Argu

A declarative CLI argument parser for F#
https://fsprojects.github.io/Argu
MIT License
453 stars 75 forks source link

Empty usage prevents line breaks between options #173

Open LiteracyFanatic opened 2 years ago

LiteracyFanatic commented 2 years ago

Description

The help message is formatted incorrectly when any of the options have an empty description.

Repro steps

Create a subcommand with empty argument descriptions. Then run the program and print the help message.

type KanjiArgs =
    | Strokes of int
    | Min_Strokes of int
    | Max_Strokes of int
    | Include_Stroke_Miscounts
    | Radicals of string
    | Skip_Code of string
    | Sh_Code of string
    | Four_Corner_Code of string
    | Deroo_Code of string
    | Reading of string
    | Nanori of string
    | Common_Only
    | Pattern of string
    interface IArgParserTemplate with
        member this.Usage =
            match this with
            | Strokes _ -> ""
            | Min_Strokes _ -> ""
            | Max_Strokes _ -> ""
            | Include_Stroke_Miscounts -> ""
            | Radicals _ -> ""
            | Skip_Code _ -> ""
            | Sh_Code _ -> ""
            | Four_Corner_Code _ -> ""
            | Deroo_Code _ -> ""
            | Reading _ -> ""
            | Nanori _ -> ""
            | Common_Only -> ""
            | Pattern _ -> ""

type Args =
    | [<CliPrefix(CliPrefix.None)>] Kanji of ParseResults<KanjiArgs>
    interface IArgParserTemplate with
        member this.Usage =
            match this with
            | Kanji _ -> ""

Expected behavior

The help message should be formatted with newlines between the options, like this.

USAGE: kensaku kanji [--help] [--strokes <int>] [--min-strokes <int>]
                     [--max-strokes <int>] [--include-stroke-miscounts]
                     [--radicals <string>] [--skip-code <string>]
                     [--sh-code <string>] [--four-corner-code <string>]
                     [--deroo-code <string>] [--reading <string>]
                     [--nanori <string>] [--common-only] [--pattern <string>]

OPTIONS:

    --strokes <int>        
    --min-strokes <int>    
    --max-strokes <int>    
    --include-stroke-miscounts
    --radicals <string>    
    --skip-code <string>   
    --sh-code <string>     
    --four-corner-code <string>
    --deroo-code <string>  
    --reading <string>     
    --nanori <string>      
    --common-only          
    --pattern <string>     
    --help                display this list of options.

Actual behavior

Instead the output looks like this.

USAGE: kensaku kanji [--help] [--strokes <int>] [--min-strokes <int>]
                     [--max-strokes <int>] [--include-stroke-miscounts]
                     [--radicals <string>] [--skip-code <string>]
                     [--sh-code <string>] [--four-corner-code <string>]
                     [--deroo-code <string>] [--reading <string>]
                     [--nanori <string>] [--common-only] [--pattern <string>]

OPTIONS:

    --strokes <int>           --min-strokes <int>       --max-strokes <int>       --include-stroke-miscounts
                              --radicals <string>       --skip-code <string>      --sh-code <string>        --four-corner-code <string>
                              --deroo-code <string>     --reading <string>        --nanori <string>         --common-only             --pattern <string>        --help                display this list of options.

Known workarounds

Using a single space instead of an empty string for the description causes newlines to be added, but there are gaps between some of the options. Here is an example using x instead of a space for visibility.


USAGE: kensaku kanji [--help] [--strokes <int>] [--min-strokes <int>]
                     [--max-strokes <int>] [--include-stroke-miscounts]
                     [--radicals <string>] [--skip-code <string>]
                     [--sh-code <string>] [--four-corner-code <string>]
                     [--deroo-code <string>] [--reading <string>]
                     [--nanori <string>] [--common-only] [--pattern <string>]

OPTIONS:

    --strokes <int>       x
    --min-strokes <int>   x
    --max-strokes <int>   x
    --include-stroke-miscounts
                          x
    --radicals <string>   x
    --skip-code <string>  x
    --sh-code <string>    x
    --four-corner-code <string>
                          x
    --deroo-code <string> x
    --reading <string>    x
    --nanori <string>     This is a very long description which needs to be
                          wrapped to multiple lines in order to fit
    --common-only         x
    --pattern <string>    x
    --help                display this list of options.

Related information

dlidstrom commented 1 year ago

Nice bug report :+1: