Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: confirm all plugins #2126

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/plugins/external_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,10 @@ impl Forge for ExternalPlugin {
if settings.paranoid {
bail!("Paranoid mode is enabled, refusing to install community-developed plugin");
}
if !prompt::confirm(format!("Would you like to install {}?", self.name))? {
if !prompt::confirm_with_all(format!(
"Would you like to install {}?",
self.name
))? {
Err(PluginNotInstalled(self.name.clone()))?
}
}
Expand Down
38 changes: 37 additions & 1 deletion src/ui/prompt.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use std::sync::Mutex;

use demand::Confirm;
use demand::{Confirm, Dialog, DialogButton};

use crate::env;
use crate::ui::ctrlc;

static MUTEX: Mutex<()> = Mutex::new(());

static SKIP_PROMPT: Mutex<bool> = Mutex::new(false);

pub fn confirm<S: Into<String>>(message: S) -> eyre::Result<bool> {
let _lock = MUTEX.lock().unwrap(); // Prevent multiple prompts at once
let _ctrlc = ctrlc::handle_ctrlc()?;
Expand All @@ -17,3 +19,37 @@ pub fn confirm<S: Into<String>>(message: S) -> eyre::Result<bool> {
let result = Confirm::new(message).run()?;
Ok(result)
}

pub fn confirm_with_all<S: Into<String>>(message: S) -> eyre::Result<bool> {
let _lock = MUTEX.lock().unwrap(); // Prevent multiple prompts at once
let _ctrlc = ctrlc::handle_ctrlc()?;

if !console::user_attended_stderr() || env::__USAGE.is_some() {
return Ok(false);
}

let mut skip_prompt = SKIP_PROMPT.lock().unwrap();
if *skip_prompt {
return Ok(true);
}

let answer = Dialog::new(message)
.buttons(vec![
DialogButton::new("Yes"),
DialogButton::new("No"),
DialogButton::new("All"),
])
.selected_button(1)
.run()?;

let result = match answer.as_str() {
"Yes" => true,
"No" => false,
"All" => {
*skip_prompt = true;
true
}
_ => false,
};
Ok(result)
}
Loading