docopt/docopt.rs

trouble with argument lists split over multiple lines

oconnor663 opened this issue · 1 comments

The following works in Python:

import docopt

__doc__ = """\
Usage: test.py [--flag]
               [--another]
"""

args = docopt.docopt(__doc__)
print(args)
$ ./test.py --flag          
{'--another': False,
 '--flag': True}
$ ./test.py --another
{'--another': True,
 '--flag': False}
$ ./test.py --flag --another
{'--another': True,
 '--flag': True}

The equivalent has trouble in docopt.rs:

#[macro_use]
extern crate serde_derive;
extern crate docopt;

const USAGE: &str = "\
Usage: test [--flag]
            [--another]
";

#[derive(Debug, Deserialize)]
struct Args {
    flag_flag: bool,
    flag_another: bool,
}

fn main() {
    let args: Args = docopt::Docopt::new(USAGE)
        .and_then(|d| d.deserialize())
        .unwrap_or_else(|e| e.exit());
    println!("{:?}", args);
}
$ ./test --flag
Args { flag_flag: true, flag_another: false }
$ ./test --another
Args { flag_flag: false, flag_another: true }
$ ./test --flag --another
Invalid arguments.

Usage: test [--flag]
            [--another]

It seems like the Rust implementation is interpreting those two lines as two separate argument lists (where the second one is allowed to omit the executable name?), rather than combining them into one. Does that sound like the right interpretation? Do you know of any workarounds currently, besides just avoiding newlines in the docstring?

Same issue for me. It's not vital, I just want to make a long list of arguments look prettier when logged to the console. 😖