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

Strange behavior if subcommand starts with program name

Open markschl opened this issue 7 years ago • 0 comments

I'm not sure whether this is expected behavior, but the following seems a bit strange to me:

static USAGE: &'static str = "
Description

Usage:
    prog subcommand <arg>

";

fn main() {
    let d = docopt::Docopt::new(USAGE).unwrap().help(true).parse().unwrap();
    println!("{:?}", d);
}

The above program works fine (cargo run -- subcommand arg). However, if the subcommand is changed to start with the binary name (new usage string: prog progsubcommand <arg> ), running cargo run -- progsubcommand arg will fail with 'Invalid arguments...'. But running cargo run -- subcommand arg will again work. The problem does not occurr on http://try.docopt.org/.

markschl avatar Aug 14 '18 09:08 markschl