inquire derive and attribute macro
simonsan opened this issue · comments
I would like to easily annotate a configuration struct, to ask the user for input for various fields and give a hint on validation:
use inquire::AskUser;
#[derive(Debug, AskUser)]
struct MyConf {
#[ask(q="Please enter password:", hide_input=true, min_len=12)]
password: Option<String>,
#[ask(q="Please enter username:", min_len=3)]
username: Option<String>,
#[ask(q="Please enter age:", range=18..=85)]
age: Option<u8>,
}
fn main() -> Result<()> {
let mut conf = MyConf::default()
conf.password()?.validate()?;
conf.username()?.validate()?;
conf.age()?.validate()?;
println!("{conf#?}");
}
I would be interested if something like this is already existing, e.g. based on inquire, or if there is any interest to add this?
This goes in the direction, I think: https://github.com/mikaelmello/inquire/tree/iw/derive/inquire-derive/src ?
I will close this one, but please feel free to comment on #65. I don't have much time to work these days.
Thanks for the hint, I searched but didn't find it, probably wrong search string. Sorry!