In some cases, I need to do validation after-the-fact.. With clap, I have access to ArgMatches which can let be print the usage. I'm not aware of a way to access that from structopt.
I'm not sure I understand, but StructOpt::clap and StructOpt::from_clap doesn't allow you to do what you need?
So it looks like this will require
let app = Opts::clap();
let matches = app.get_matches();
let opts = Opts::from_clap(&matches);
....
if error_case {
bail!("Describe error\n{}", matches.usage());
}
I assume this will be the best we should get. Anything more would require somehow keeping the matches around which would probably be too much for the few cases where this is needed.
Granted, my main use case for manual validation is the problems I've run into with raw. Most or all I could do with clap if it was easier to do and didn't become too verbose (#104 would help).
Thus this issuse is fixed for you? You can close it if yes, or refine the question/evolution else.
It might be nice to more explicitly document the workflow for accessing the matches (not the exact use case). It is sometimes hard with macros to know whats going on. It is nice that you provide a lot of functionality through a trait, improving discoverability but it would still be nice to note the relationship of the provided parts and then fit them together to solve a need.
Feel free to re-open if you want to do that.
TODO: better document that #[derive(StructOpt)] gives you acces to the structopt::StructOpt trait, with other things that just from_args.
related to this (maybe), in clap, I can call app.print_usage(). How does one do this in structopt?
Opt::clap().print_usage();
great thanks! (absolutely fantastic crate by the way. really makes creating a cli a no brainer)
Glad to help here. How do you think this would be better documented, @TeXitoi?
@thiagoarrais I think we should explicitly state that StructOpt trait has more than just from_args function. Perhaps somewhere in How to derive section.
I validate @CreepySkeleton's suggestion.
Nice. I've sent a PR. Let's continue this convo there.
Most helpful comment
@thiagoarrais I think we should explicitly state that
StructOpttrait has more than justfrom_argsfunction. Perhaps somewhere inHow to derivesection.