T'interwebs, I'm confused. I'm writing a program to learn Rust, and the argument parser is behaving oddly. I give it one argument, and it acts as though I've given it another. Please can someone point out the bit where I've been stupid? gist.github.com/arafel/2d65e… cc @dsilverstone
1
I'm afraid I've lost the knack to read clap parser chains. I use the derive approach where you define your CLI as structs and enums
3
Though what it looks like is that your `update` argument has the value `search` which is kinda expected - it looks to me like you intended `update` and `search` to be subcommands of `groups` no?
1
I did, but I was expecting β€œupdate” to be Boolean, ie if the flag is present the value is true, no arguments or anything. search takes an argument (what to search for), update doesn’t. Did I get that wrong?
1
Replying to @arafel2
I think without .long() or .short() the Arg is treated as positional.

Apr 23, 2022 Β· 7:22 PM UTC

2
Replying to @dsilverstone
Thanks, I’ll try that. I did find if I re-ordered the options it worked, which was helpful but obviously not so good as knowing why. πŸ™‚ If it doesn’t help I’ll try their Github issues list.
Replying to @dsilverstone
Good psychic debugging, that seems to fix it. Thanks! So far I've found if stuff gets past rustc then it mostly works, so that one threw me a bit. :-) Enjoying Rust as a whole though.
1
Sadly if the semantics of something are valid but not what you wanted, rustc won't catch it :D