client: error out on non-tty interactivity
All checks were successful
All checks were successful
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use std::io::IsTerminal;
|
||||
|
||||
use clap::Parser;
|
||||
use clap_complete::ArgValueCompleter;
|
||||
use dialoguer::Confirm;
|
||||
@@ -78,6 +80,15 @@ pub async fn create_users(
|
||||
.filter_map(|(username, result)| result.as_ref().ok().map(|()| username))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if !std::io::stdin().is_terminal()
|
||||
&& !args.no_password
|
||||
&& !successfully_created_users.is_empty()
|
||||
{
|
||||
anyhow::bail!(
|
||||
"Cannot prompt for passwords in non-interactive mode. Use --no-password to skip setting passwords."
|
||||
);
|
||||
}
|
||||
|
||||
for username in successfully_created_users {
|
||||
if !args.no_password
|
||||
&& Confirm::new()
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::io::IsTerminal;
|
||||
|
||||
use clap::Parser;
|
||||
use clap_complete::ArgValueCompleter;
|
||||
use dialoguer::Confirm;
|
||||
@@ -41,6 +43,12 @@ pub async fn drop_databases(
|
||||
anyhow::bail!("No database names provided");
|
||||
}
|
||||
|
||||
if !std::io::stdin().is_terminal() && !args.yes {
|
||||
anyhow::bail!(
|
||||
"Cannot prompt for confirmation in non-interactive mode. Use --yes to automatically confirm."
|
||||
);
|
||||
}
|
||||
|
||||
if !args.yes {
|
||||
let confirmation = Confirm::new()
|
||||
.with_prompt(format!(
|
||||
@@ -53,7 +61,6 @@ pub async fn drop_databases(
|
||||
))
|
||||
.interact()?;
|
||||
|
||||
//
|
||||
if !confirmation {
|
||||
// TODO: should we return with an error code here?
|
||||
println!("Aborting drop operation.");
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use std::io::IsTerminal;
|
||||
|
||||
use clap::Parser;
|
||||
use clap_complete::ArgValueCompleter;
|
||||
use dialoguer::Confirm;
|
||||
@@ -41,6 +43,12 @@ pub async fn drop_users(
|
||||
anyhow::bail!("No usernames provided");
|
||||
}
|
||||
|
||||
if !std::io::stdin().is_terminal() && !args.yes {
|
||||
anyhow::bail!(
|
||||
"Cannot prompt for confirmation in non-interactive mode. Use --yes to automatically confirm."
|
||||
);
|
||||
}
|
||||
|
||||
if !args.yes {
|
||||
let confirmation = Confirm::new()
|
||||
.with_prompt(format!(
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::{
|
||||
collections::{BTreeMap, BTreeSet},
|
||||
io::IsTerminal,
|
||||
};
|
||||
|
||||
use anyhow::Context;
|
||||
use clap::{Args, Parser};
|
||||
@@ -213,6 +216,11 @@ pub async fn edit_database_privileges(
|
||||
};
|
||||
|
||||
let diffs: BTreeSet<DatabasePrivilegesDiff> = if privs.is_empty() {
|
||||
if !std::io::stdin().is_terminal() {
|
||||
anyhow::bail!(
|
||||
"Cannot launch editor in non-interactive mode. Please provide privileges via command line arguments."
|
||||
);
|
||||
}
|
||||
let privileges_to_change =
|
||||
edit_privileges_with_editor(&existing_privilege_rows, use_database.as_ref())?;
|
||||
diff_privileges(&existing_privilege_rows, &privileges_to_change)
|
||||
@@ -275,7 +283,8 @@ pub async fn edit_database_privileges(
|
||||
println!("The following changes will be made:\n");
|
||||
println!("{}", display_privilege_diffs(&diffs));
|
||||
|
||||
if !args.yes
|
||||
if std::io::stdin().is_terminal()
|
||||
&& !args.yes
|
||||
&& !Confirm::new()
|
||||
.with_prompt("Do you want to apply these changes?")
|
||||
.default(false)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::path::PathBuf;
|
||||
use std::{io::IsTerminal, path::PathBuf};
|
||||
|
||||
use anyhow::Context;
|
||||
use clap::Parser;
|
||||
@@ -88,6 +88,11 @@ pub async fn passwd_user(
|
||||
.context("Failed to read password from stdin")?;
|
||||
buffer.trim().to_string()
|
||||
} else {
|
||||
if !std::io::stdin().is_terminal() {
|
||||
anyhow::bail!(
|
||||
"Cannot prompt for password in non-interactive mode. Use --stdin or --password-file to provide the password."
|
||||
);
|
||||
}
|
||||
read_password_from_stdin_with_double_check(&args.username)?
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user