docopt.rs icon indicating copy to clipboard operation
docopt.rs copied to clipboard

improve usage string failure mode on parse error

Open dovreshef opened this issue 10 years ago • 4 comments

When using tab characters instead of spaces inside the usage string the resulting help message (or any output) is not the expected output.

Test case: In the following usage string from the default example replace the spaces between the options and their decription with tab. Do the same with any leading space:

static USAGE: &'static str = "

Usage:   cp [-a] <source> <dest>
         cp [-a] <source>... <dir>

Options:
    -a, --archive   Copy everything.
";

The result when running the resulting executable with no input:

 Extraneous text '      Copy everything.' in option description '-a --archive   Copy everything.'.

expected:

Invalid arguments.

Usage:    cp [-a] <source> <dest>
           cp [-a] <source>... <dir>

dovreshef avatar Apr 15 '15 21:04 dovreshef

The error is a bit cryptic, but correct. From the Docopt spec:

Use two spaces to separate options with their informal description:

I don't have any opinions on whether tabs should be allowed or not, but you should propose this change to Docopt proper.

cc @keleshev

BurntSushi avatar Apr 15 '15 21:04 BurntSushi

I have no problem with the spec. I simply did not understand that the output was indicating an error with the usage string. I thought it the result of some problems with the parser :(. Just a suggestion, but maybe you could add a prefix to the message indicating that it is a usage string parse error..

dovreshef avatar Apr 16 '15 14:04 dovreshef

@dovreshef Ah, I misunderstood. I've re-opened and changed the title to be more specific. Thanks!

BurntSushi avatar Apr 16 '15 14:04 BurntSushi

Use two spaces to separate options with their informal description:

It more looks like "at least two spaces".

pravic avatar Jun 08 '18 18:06 pravic