Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

trouble with argument lists split over multiple lines #244

Open
oconnor663 opened this issue Sep 20, 2018 · 1 comment
Open

trouble with argument lists split over multiple lines #244

oconnor663 opened this issue Sep 20, 2018 · 1 comment

Comments

@oconnor663
Copy link

oconnor663 commented Sep 20, 2018

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?

@gskapka
Copy link

gskapka commented Oct 27, 2018

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. 😖

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants