-
-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve the -u
flag once clap is ready
#92
Comments
We can't have the `-u <mode> <file> <mime>` style yet, but clap-rs/clap#88 might help with that at some point. Related to #92 and #81
Should be ready with 0.7.1 on crates.io ;) |
You can watch the development stream in multiple sessions on youtube: |
I'm really enjoying the videos as it's showing me from an outside perspective things I can improve! I haven't watched part 2, as it's still processing - but I noticed in part 1 you mentioned possible values for each different value of The gist is something like: arg_enum!{
#[derive(Debug)]
enum FirstValue {
value1,
value2,
value3
}
}
arg_enum!{
enum SecondValue {
value1,
value2
}
}
//...
for (i, val) in values_vec.iter().enumerate() {
match i {
0 => {
// .unwrap() just for brevity
let first_val = val.parse::<FirstValue>().unwrap();
println!("First val: {:?}", first_val);
},
1 => let second_val = val.parse::<SecondValue>().unwrap(),
_ => ()
}
} |
@kbknapp Thanks a bunch for the hints ! It's quite cool to see you find the videos useful ! Actually I watched part of the sessions myself just to find (and fix) the mistakes I did. It also gave me a clearer view on the situation, which led to a proposition for improvement. match "simple".parse() {
Ok(Protocol::Simple) => <this branch should match>,
Ok(Protocol::Resumable) => ...,
Err(err) => ... ,
} From the docs and the implementation, it didn't look like that would work, but I admittedly didn't try it either. |
PR 105 adds ascii case insensitivity for enum variants. So you could have an enum arg_enum! {
enum SomeVal {
ValOne,
ValTwo
}
}
// ...
match value_t_or_exit!(matches.value_of("my-enum"), SomeVal) {
SomeVal::ValOne =>(),
SomeVal::ValTwo =>(),
}
// "valone".parse::<SomeVal>() works too If the user ran |
Thanks again ! Now it is exactly what I need, and I will use it as soon as the PR was merged. |
I'd like to have
-u <mode> <file> <mime>
, and all we need is an improvement, as suggested in this issue.The text was updated successfully, but these errors were encountered: