mirror of
https://github.com/TECHNOFAB11/pay-respects.git
synced 2025-12-11 22:10:09 +01:00
feat: noconfirm mode
This commit is contained in:
parent
885dc081e1
commit
5f521650c8
4 changed files with 48 additions and 0 deletions
|
|
@ -55,6 +55,7 @@ fn main() -> Result<(), std::io::Error> {
|
|||
match data.mode {
|
||||
Suggestion => modes::suggestion(&mut data),
|
||||
Echo => modes::echo(&mut data),
|
||||
NoConfirm => modes::noconfirm(&mut data),
|
||||
Cnf => modes::cnf(&mut data),
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ use crate::shell::Data;
|
|||
use crate::suggestions;
|
||||
use crate::suggestions::suggest_candidates;
|
||||
use crate::system;
|
||||
use crate::style::highlight_difference;
|
||||
use colored::Colorize;
|
||||
use inquire::*;
|
||||
use pay_respects_utils::evals::best_matches_path;
|
||||
|
|
@ -50,6 +51,43 @@ pub fn echo(data: &mut Data) {
|
|||
println!("{}", data.candidates.join("<PR_BR>\n"));
|
||||
}
|
||||
|
||||
pub fn noconfirm(data: &mut Data) {
|
||||
let mut last_command;
|
||||
|
||||
loop {
|
||||
last_command = data.command.clone();
|
||||
suggest_candidates(data);
|
||||
if data.candidates.is_empty() {
|
||||
break;
|
||||
};
|
||||
|
||||
let candidate = data.candidates[0].clone();
|
||||
eprintln!("{}",
|
||||
highlight_difference(data, &candidate).unwrap()
|
||||
);
|
||||
data.update_suggest(&candidate);
|
||||
data.candidates.clear();
|
||||
|
||||
let execution = suggestions::confirm_suggestion(data);
|
||||
if execution.is_ok() {
|
||||
return;
|
||||
} else {
|
||||
data.update_command(&data.suggest.clone().unwrap());
|
||||
let msg = Some(execution.err().unwrap());
|
||||
data.update_error(msg);
|
||||
|
||||
let retry_message = format!("{}...", t!("retry"));
|
||||
eprintln!("\n{}\n", retry_message.cyan().bold());
|
||||
}
|
||||
}
|
||||
eprintln!("{}: {}\n", t!("no-suggestion"), last_command.red());
|
||||
eprintln!(
|
||||
"{}\n{}",
|
||||
t!("contribute"),
|
||||
option_env!("CARGO_PKG_REPOSITORY").unwrap_or("https://github.com/iffse/pay-respects/")
|
||||
);
|
||||
}
|
||||
|
||||
pub fn cnf(data: &mut Data) {
|
||||
let shell = data.shell.clone();
|
||||
let mut split_command = data.split.clone();
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ pub const PRIVILEGE_LIST: [&str; 2] = ["sudo", "doas"];
|
|||
pub enum Mode {
|
||||
Suggestion,
|
||||
Echo,
|
||||
NoConfirm,
|
||||
Cnf,
|
||||
}
|
||||
pub struct Init {
|
||||
|
|
@ -391,6 +392,7 @@ pub fn run_mode() -> Mode {
|
|||
Ok(mode) => match mode.as_str() {
|
||||
"suggestion" => Mode::Suggestion,
|
||||
"cnf" => Mode::Cnf,
|
||||
"noconfirm" => Mode::NoConfirm,
|
||||
"echo" => Mode::Echo,
|
||||
_ => {
|
||||
eprintln!("Invalid mode: {}", mode);
|
||||
|
|
|
|||
|
|
@ -24,6 +24,13 @@ extern crate rust_i18n;
|
|||
i18n!("i18n", fallback = "en", minify_key = true);
|
||||
|
||||
fn main() -> Result<(), std::io::Error> {
|
||||
let mode = std::env::var("_PR_MODE");
|
||||
if let Ok(mode) = mode {
|
||||
if mode.as_str() == "noconfirm" {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
let command = std::env::var("_PR_LAST_COMMAND").expect("_PR_LAST_COMMAND not set");
|
||||
let error = std::env::var("_PR_ERROR_MSG").expect("_PR_ERROR_MSG not set");
|
||||
colored::control::set_override(true);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue