From dadfa786efaa7bab910d952677555f180f44f614 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Wed, 7 Aug 2024 16:43:55 +0200 Subject: [PATCH] create-user: ask for password by default --- src/cli/user_command.rs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/cli/user_command.rs b/src/cli/user_command.rs index 08c4744..32ebc1f 100644 --- a/src/cli/user_command.rs +++ b/src/cli/user_command.rs @@ -38,6 +38,10 @@ pub enum UserCommand { pub struct UserCreateArgs { #[arg(num_args = 1..)] username: Vec, + + /// Do not ask for a password, leave it unset + #[clap(long)] + no_password: bool, } #[derive(Parser)] @@ -81,8 +85,30 @@ async fn create_users(args: UserCreateArgs, conn: &mut MySqlConnection) -> anyho for username in args.username { if let Err(e) = crate::core::user_operations::create_database_user(&username, conn).await { eprintln!("{}", e); - eprintln!("Skipping..."); + eprintln!("Skipping...\n"); + continue; + } else { + println!("User '{}' created.", username); } + + if !args.no_password + && Confirm::new() + .with_prompt(format!( + "Do you want to set a password for user '{}'?", + username + )) + .interact()? + { + change_password_for_user( + UserPasswdArgs { + username, + password_file: None, + }, + conn, + ) + .await?; + } + println!(""); } Ok(()) }