These are chat archives for kbknapp/clap-rs

17th
Aug 2017
Bruce Adams
@bruceadams
Aug 17 2017 12:20
My attempt to use structopt hit a wall when I wanted options for subcommands. Looking at clap issues, I found stomp-rs mentioned in kbknapp/clap-rs#835 (which is now closed). stomp-rs aims to do what I hope for. I've been fiddling with stomp-rs to get it working. I'm pretty close. Is there a strong preference for working from structopt instead of stomp-rs?
Bruce Adams
@bruceadams
Aug 17 2017 12:40
I need to get clearance from my employer to publish my work on stomp-rs. In the past, I've gotten that clearance quickly, so I hope I'll be able to show code today. I'm more than happy to work to get the code to fit within clap instead of standing off to the side.
Kevin K.
@kbknapp
Aug 17 2017 14:46
@bruceadams When I bring structopt into the mainline, if there is a particular set of missing functionality I'm very much open to adding it
This is what I mean by making minor changes. As far as if there is a preference to using structopt over stomp-rs, there isn't. structopt has a lot of popularity, so I may lean that way, but like I said, if there is missing functionality I'm open to considering adding it and taking the best of both worlds
Bruce Adams
@bruceadams
Aug 17 2017 16:09
Well, structopt was published on crates.io and stomp-rs wasn't which explains popularity; not to mention stomp-rs wasn't quite working when I started fiddling with it a few days ago. Anyway, what I want is something that works for me and I'm very happy to contribute to making that happen. If I can align with what you and anyone else is doing, that'd be great. To give you a sense of my big target, this is my current use of Clap https://github.com/bruceadams/wdscli/blob/master/src/cli.rs — more than 500 lines chained onto App::new. It's the subcommands with options that structopt falls down on. structopt demands an enum with anonymous structs, which appears to be unusable in ordinary Rust code.
stomp-rs, even in the examples, does subcommand options as named structs, which is much easier to consume in Rust code.
Kevin K.
@kbknapp
Aug 17 2017 17:41
Gotcha, that's probably one of the changes that I'd like to make when pulling in structopt (or whichever code I end up using) as what you're listing is not only a common use of clap, but I'd venture so far as to say the most common use of clap. My number one priority is making the code ergonomic for end users, which is what may drive some of the changes. I'm not familiar enough with stomp-rs to say how close or far it is from my goal but will take a hard look at it once I reach that part of the v3 build.
My big goals for this structopt/stomp-rs part of v3 are:
  • custom "Args" struct -> clap::App via CustomDerive
  • clap::ArgMatches -> custom "Args" struct via CustomDerive
I'm almost to that part of the v3 build. My local v3 branch is refactored, it compiles, but I need to make all the tests pass. Once the tests pass I can start implementing all the new features, and this CustomDerive piece is top of my list
Kevin K.
@kbknapp
Aug 17 2017 17:47
A secondary goal of the CustomDerive piece is allowing one to use structs/enums variants as arg keys, instead of strings.
Casey Rodarmor
@casey
Aug 17 2017 19:45
Is there a way to stop parsing flags/options (-f/--foo) after accepting the first positional argument?
Basically like an implicit -- after the first positional argument, so that everything after that is treated as a positional argument, even if it matches a flag.
Kevin K.
@kbknapp
Aug 17 2017 21:25
Try AppSettings::TrailingVarArg or Arg::last
I'm on mobile right now, or I'd link to the docs ;)
Bruce Adams
@bruceadams
Aug 17 2017 22:23
This https://github.com/bruceadams/stomp-rs/tree/my-twiddles fixes the most glaring problems I've tripped into in stomp-rs. Things compile. Simple runs work fine, including that the help text generally looks right. I do some get panics at run-time. I guess I should publish my big example use...
Kevin K.
@kbknapp
Aug 17 2017 22:41
Yeah if you've got an example use case that would help :)
Bruce Adams
@bruceadams
Aug 17 2017 23:00
I have an event in two minutes. I have figured out that the panic is a unreachable!() generated by stomp-rs; it's not panicking in Clap code. I'll get make more stuff public soonish, but that might mean tomorrow.