diff --git a/src/cli/user_command.rs b/src/cli/user_command.rs index 3579ec8..3db7e80 100644 --- a/src/cli/user_command.rs +++ b/src/cli/user_command.rs @@ -62,6 +62,9 @@ pub struct UserPasswdArgs { pub struct UserShowArgs { #[arg(num_args = 0..)] username: Vec, + + #[clap(short, long)] + json: bool, } pub async fn handle_command(command: UserCommand, mut conn: MySqlConnection) -> anyhow::Result<()> { @@ -193,16 +196,20 @@ async fn show_users(args: UserShowArgs, conn: &mut MySqlConnection) -> anyhow::R result }; - for user in users { - println!( - "User '{}': {}", - &user.user, - if user.has_password { - "password set." - } else { - "no password set." - } - ); + if args.json { + println!("{}", serde_json::to_string_pretty(&users)?); + } else { + for user in users { + println!( + "User '{}': {}", + &user.user, + if user.has_password { + "password set." + } else { + "no password set." + } + ); + } } Ok(()) diff --git a/src/core/user_operations.rs b/src/core/user_operations.rs index 8059c76..2b0c67e 100644 --- a/src/core/user_operations.rs +++ b/src/core/user_operations.rs @@ -100,6 +100,7 @@ pub struct DatabaseUser { #[sqlx(rename = "User")] pub user: String, + #[serde(skip)] #[sqlx(rename = "Host")] pub host: String,