client: add --fail flag for show-* commands

This commit is contained in:
2025-12-01 15:19:42 +09:00
parent e05a72894f
commit 1af9748530
3 changed files with 30 additions and 0 deletions

View File

@@ -20,6 +20,10 @@ pub struct ShowDbArgs {
/// Print the information as JSON
#[arg(short, long)]
json: bool,
/// Return a non-zero exit code if any of the results were erroneous
#[arg(short, long)]
fail: bool,
}
pub async fn show_databases(
@@ -36,12 +40,14 @@ pub async fn show_databases(
// TODO: collect errors for json output.
let mut contained_errors = false;
let database_list = match server_connection.next().await {
Some(Ok(Response::ListDatabases(databases))) => databases
.into_iter()
.filter_map(|(database_name, result)| match result {
Ok(database_row) => Some(database_row),
Err(err) => {
contained_errors = true;
eprintln!("{}", err.to_error_message(&database_name));
eprintln!("Skipping...");
println!();
@@ -76,5 +82,9 @@ pub async fn show_databases(
table.printstd();
}
if args.fail && contained_errors {
std::process::exit(1);
}
Ok(())
}

View File

@@ -22,6 +22,10 @@ pub struct ShowPrivsArgs {
/// Print the information as JSON
#[arg(short, long)]
json: bool,
/// Return a non-zero exit code if any of the results were erroneous
#[arg(short, long)]
fail: bool,
}
pub async fn show_database_privileges(
@@ -35,12 +39,14 @@ pub async fn show_database_privileges(
};
server_connection.send(message).await?;
let mut contained_errors = false;
let privilege_data = match server_connection.next().await {
Some(Ok(Response::ListPrivileges(databases))) => databases
.into_iter()
.filter_map(|(database_name, result)| match result {
Ok(privileges) => Some(privileges),
Err(err) => {
contained_errors = true;
eprintln!("{}", err.to_error_message(&database_name));
eprintln!("Skipping...");
println!();
@@ -96,5 +102,9 @@ pub async fn show_database_privileges(
table.printstd();
}
if args.fail && contained_errors {
std::process::exit(1);
}
Ok(())
}

View File

@@ -20,6 +20,10 @@ pub struct ShowUserArgs {
/// Print the information as JSON
#[arg(short, long)]
json: bool,
/// Return a non-zero exit code if any of the results were erroneous
#[arg(short, long)]
fail: bool,
}
pub async fn show_users(
@@ -37,12 +41,14 @@ pub async fn show_users(
anyhow::bail!(err);
}
let mut contained_errors = false;
let users = match server_connection.next().await {
Some(Ok(Response::ListUsers(users))) => users
.into_iter()
.filter_map(|(username, result)| match result {
Ok(user) => Some(user),
Err(err) => {
contained_errors = true;
eprintln!("{}", err.to_error_message(&username));
eprintln!("Skipping...");
None
@@ -89,5 +95,9 @@ pub async fn show_users(
table.printstd();
}
if args.fail && contained_errors {
std::process::exit(1);
}
Ok(())
}