These are chat archives for kbknapp/clap-rs

16th
Aug 2017
Jeroen Bollen
@Binero
Aug 16 2017 14:17
Is there a way to require a subcommand in clap?
And if not, how do you guys generally handle the situation where none is supplied, but one is required?
Jonas Platte
@jplatte
Aug 16 2017 14:18
@Binero Read the last 10 messages in this channel :P
Jeroen Bollen
@Binero
Aug 16 2017 14:18
Oh wow what a coincidence :P
Cheers, I think I am going with AppSettings::SubcommandRequired :D
Kevin K.
@kbknapp
Aug 16 2017 15:23
Perhaps I should improve the docs on this issue :P
Jeroen Bollen
@Binero
Aug 16 2017 15:24
Just adding a little reference to it in .subcommand() would be nice. It's a pretty big crate to quickly read through to see what it all supports. :)
Kevin K.
@kbknapp
Aug 16 2017 18:03
agreed
For 3.x I'm trying do away with App vs SubCommand structs, since they're actually just the same thing. And make everything App so there is less confusion and documentation is easier to find
Essentially, subcommand(SubCommand::with_name("foo")) -> subcommand(App::new("foo"))
it's less typing too
Jeroen Bollen
@Binero
Aug 16 2017 18:55
@kbknapp Does this crate have some sort of basic handling for numeric arguments, or should we just use a validator and then parse().unwrap() the string?
Kevin K.
@kbknapp
Aug 16 2017 18:56
There is a macro that boils the "32".parse() operations down for you, or even handles generating an error on failed parse and exiting for you, but other than that no.
look at value_t!
There's also values_t! for handling options that accept multiple values
Finally, there's the or_exit! variants that handle the pretty errors and exiting if needed
Jeroen Bollen
@Binero
Aug 16 2017 18:58
Yeah, I am looking at that. Does that print an error as well? Or do I have to do that still?
ah
The or_exit ones are deprecated though, it seems.
Kevin K.
@kbknapp
Aug 16 2017 18:59
Yeah, in Rust style, you can map the results
value_t!(matches.value_of("length"), u32).unwrap_or_else(|e| e.exit());
the or_exit variants won't be removed until 3.x
Jeroen Bollen
@Binero
Aug 16 2017 19:00
Yeah I see, I misread the e.exit as an exit() call to stop the program using std::process::exit
Kevin K.
@kbknapp
Aug 16 2017 19:01
It ultimately does that, but first does the clap style error messages
Jeroen Bollen
@Binero
Aug 16 2017 19:01
Yeah
That'll work probably, thanks!
Kevin K.
@kbknapp
Aug 16 2017 19:01
no prob~
!*
Also, a big push for 3.x is to handle converting your ArgMatches struct into true Rust types automatically...so you won't have to rely on this macro business
Denis Lisov
@tanriol
Aug 16 2017 19:02
Is 3.x going to include something like structopt too?
Jeroen Bollen
@Binero
Aug 16 2017 19:03
That'd be very neat, I'd be interested to see how it's going to do that
Yes, the goal is actually to bring structopt into mainline clap
Unfortunately, I just haven't had a ton of time to work on it lately due to my day job
Should be soon though, as the craziness for my day job is winding down finally!
Denis Lisov
@tanriol
Aug 16 2017 19:08
Why does the blog post say that IntoApp will be nightly-only? structopt is doing a form of this on stable now.
Kevin K.
@kbknapp
Aug 16 2017 19:09
#[clap(short = "v", long = "verbose")] parts like this would require nightly
IntoApp would work on stable
Denis Lisov
@tanriol
Aug 16 2017 19:16
They do work on stable, although limited to string values only.
Kevin K.
@kbknapp
Aug 16 2017 19:26
Ah ok, that was a misunderstanding on my part then
That's even better then!
If I can pull in structopt verbatim that'd be the best option for me. There may have to be minor changes, but I don't want to duplicate work needlessly
The author of structopt is on board as well
Denis Lisov
@tanriol
Aug 16 2017 19:30
Sounds exciting!