These are chat archives for kbknapp/clap-rs

20th
Apr 2016
Callum Styan
@cstyan
Apr 20 2016 18:54
anyone around? I can't get the unstable features to work :(
Kevin K.
@kbknapp
Apr 20 2016 19:08
What are you trying to use?
Callum Styan
@cstyan
Apr 20 2016 19:22
@kbknapp the crate_authors! macro
I'm using the latest version of clap via git in my dependencies
Callum Styan
@cstyan
Apr 20 2016 20:07
the crate_version! macro works but not the crate_authors!
I get the error src/main.rs:9:25: 9:41 error: environment variable CARGO_PKG_AUTHORS not defined
src/main.rs:9 .author(crate_authors!()) and I have authors set inside my cargo file
Kevin K.
@kbknapp
Apr 20 2016 20:14
Are you using a nightly compiler?
Or rather a nightly cargo
Because the CARGO_PKG_AUTHORS hasn't made it into stable yet which is why it's unstable in clap
Callum Styan
@cstyan
Apr 20 2016 20:43
no I don't think so
Kevin K.
@kbknapp
Apr 20 2016 20:48
Ah ok, I'd recommend something like HTTPS://rustup.RS
It's a super easy way to maintain both a stable and nightly rustc/cargo
It's in beta right now but I've been using it without issue
Callum Styan
@cstyan
Apr 20 2016 20:52
Alright I'll take a look
I have a few more questions if you have some time
I'm wondering what the best way is to handle integer arguments when the value passed doesn't match the type of the argument
Callum Styan
@cstyan
Apr 20 2016 20:58
I'd like to return a custom error message and exit rather than just an invalid value default error
for example: let num = value_t!(matches, "num", u8).unwrap();
Kevin K.
@kbknapp
Apr 20 2016 20:59
Look at Arg::validator
I'm on mobile right now so I can't pull the actual docs up, but that'll give you a chance to do exactly that
Callum Styan
@cstyan
Apr 20 2016 21:02
awesome, I'll take a look
thanks!
Kevin K.
@kbknapp
Apr 20 2016 21:17
No prob!
Callum Styan
@cstyan
Apr 20 2016 21:22
it it possible to use the validator when parsing arguments from a yaml file?
Callum Styan
@cstyan
Apr 20 2016 21:33
and get access to the name of the argument we're validating within the validator? I see that it passes self and f
Callum Styan
@cstyan
Apr 20 2016 22:01
ah okay, passing self to the validator function just assigns self.validator to f
Kevin K.
@kbknapp
Apr 20 2016 22:41
Currently you can't assign a validator in yaml, but you can create the instance from yaml and just all but the validator in the yaml file, then in the regular source add the validator
Callum Styan
@cstyan
Apr 20 2016 22:53
@kbknapp trying to figure out how to do that now, trying to access the arg via Arg::with_name throws a duplicate error. How can I access the argument that's already been parsed from the yml file?
also it seems like a macro might be the solution for getting the name of the argument in the validator err
Kevin K.
@kbknapp
Apr 20 2016 22:57
Once the Arg instance has been added to the App instance you can't access it anymore (although that is listed in the issues to change hopefully soon). A workaround is to define the App instance in yaml, and a separate Arg instance from yaml, then in regular source add the validator to this outlying Arg and add it to the App instance
kbknapp/clap-rs#458
Callum Styan
@cstyan
Apr 20 2016 23:31
arg::from_yaml() requires a btree?
Kevin K.
@kbknapp
Apr 20 2016 23:37
Yeah that's what the yaml lib returns or rather wraps
Actually if you'd like, file an issue requesting an easier way to create only an Arg instance from yaml so I can start tracking it
Callum Styan
@cstyan
Apr 20 2016 23:37
will do
Kevin K.
@kbknapp
Apr 20 2016 23:38
If you look at the SRC for App::from_yaml you'll see how it passes args
Callum Styan
@cstyan
Apr 20 2016 23:38
can I use ArgGroup::from_yaml, or rather can I do app.ArgGroup = ?
I can't find what struct fields App has
Kevin K.
@kbknapp
Apr 20 2016 23:39
The fields aren't supposed to be used externally, you can use App::group
Although technically theres nothing stopping you from using them since they're public, but hidden
Callum Styan
@cstyan
Apr 20 2016 23:40
:thumbsup:
Callum Styan
@cstyan
Apr 20 2016 23:48
sorry, I'm still confused
how do I get access to the arguments within the ArgGroup after calling from_yml
Kevin K.
@kbknapp
Apr 20 2016 23:50
Can you show the source of what you're trying to do?
Callum Styan
@cstyan
Apr 20 2016 23:53
I just want to parse arguments from a yaml file and then apply validators to arguments based on the argument name, so I have let args = ArgGroup::from_yaml(load_yaml!(yaml_file));