Skip to content
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

inquire derive and attribute macro #212

Closed
simonsan opened this issue Jan 3, 2024 · 3 comments
Closed

inquire derive and attribute macro #212

simonsan opened this issue Jan 3, 2024 · 3 comments

Comments

@simonsan
Copy link

simonsan commented Jan 3, 2024

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?

@simonsan
Copy link
Author

simonsan commented Jan 3, 2024

This goes in the direction, I think: https://github.com/mikaelmello/inquire/tree/iw/derive/inquire-derive/src ?

@IniterWorker
Copy link
Collaborator

I will close this one, but please feel free to comment on #65. I don't have much time to work these days.

@simonsan
Copy link
Author

simonsan commented Jan 3, 2024

Thanks for the hint, I searched but didn't find it, probably wrong search string. Sorry!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants