40 lines
1004 B
Rust
40 lines
1004 B
Rust
|
use yunohost_api::{YunohostUsers, Username};
|
||
|
|
||
|
use std::io::{BufRead, Stdin, stdin};
|
||
|
use std::str::FromStr;
|
||
|
|
||
|
fn acquire_loop<T: FromStr>(input: &Stdin, message: &str) -> T
|
||
|
where <T as FromStr>::Err: std::fmt::Display {
|
||
|
loop {
|
||
|
println!("{message}");
|
||
|
let value = input.lock().lines().next().unwrap().unwrap();
|
||
|
match T::from_str(&value) {
|
||
|
Ok(v) => {
|
||
|
return v;
|
||
|
}, Err(e) => {
|
||
|
println!("{}", e);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#[tokio::main(flavor = "current_thread")]
|
||
|
async fn main() {
|
||
|
env_logger::init();
|
||
|
|
||
|
let input = stdin();
|
||
|
let users = YunohostUsers::new(500).await.unwrap();
|
||
|
|
||
|
loop {
|
||
|
println!("Welcome to Yunohost! What user would you like to know about?");
|
||
|
|
||
|
let username: Username = acquire_loop(&input, "Username:");
|
||
|
|
||
|
if users.get_user(&username).await.unwrap() {
|
||
|
println!("User found!");
|
||
|
} else {
|
||
|
println!("User not found!");
|
||
|
}
|
||
|
}
|
||
|
}
|