fix: noconfirm auto-selects first AUR match
This commit is contained in:
@@ -188,18 +188,33 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let context = AppContext::new();
|
||||
|
||||
if let Some(command) = cli.command {
|
||||
run_command(&context, command, cli.force)?;
|
||||
run_command(&context, command, cli.force, cli.noconfirm)?;
|
||||
} else {
|
||||
let mut cmd = Cli::command();
|
||||
cmd.print_help()?;
|
||||
launch_tui_or_help()?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn run_command(context: &AppContext, command: Commands, force: bool) -> Result<(), Box<dyn std::error::Error>> {
|
||||
fn launch_tui_or_help() -> Result<(), Box<dyn std::error::Error>> {
|
||||
#[cfg(feature = "tui")]
|
||||
{
|
||||
use std::io::IsTerminal;
|
||||
if io::stdin().is_terminal() && io::stdout().is_terminal() {
|
||||
if let Err(error) = cub_tui::run() {
|
||||
eprintln!("TUI error: {error}");
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
let mut cmd = Cli::command();
|
||||
cmd.print_help()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn run_command(context: &AppContext, command: Commands, force: bool, noconfirm: bool) -> Result<(), Box<dyn std::error::Error>> {
|
||||
match command {
|
||||
Commands::Install { package } => install_package(context, &package, force)?,
|
||||
Commands::Install { package } => install_package(context, &package, force, noconfirm)?,
|
||||
Commands::Search { query } => search_packages(context, &query)?,
|
||||
Commands::Info { package } => show_aur_info(&package)?,
|
||||
Commands::Sync => sync_sources()?,
|
||||
@@ -382,7 +397,7 @@ fn new_pkg_callback() -> Rc<RefCell<IndicatifCallback>> {
|
||||
Rc::new(RefCell::new(callback))
|
||||
}
|
||||
|
||||
fn install_package(context: &AppContext, package: &str, force: bool) -> Result<(), Box<dyn std::error::Error>> {
|
||||
fn install_package(context: &AppContext, package: &str, force: bool, noconfirm: bool) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if cfg!(not(target_os = "redox")) {
|
||||
println!("Searching AUR for {package}...");
|
||||
let client = AurClient::new();
|
||||
@@ -394,6 +409,12 @@ fn install_package(context: &AppContext, package: &str, force: bool) -> Result<(
|
||||
let pkg = exact.unwrap_or(&results[0]);
|
||||
|
||||
if exact.is_none() && results.len() > 1 {
|
||||
if noconfirm {
|
||||
let selected = &results[0];
|
||||
println!("Auto-selecting first match: {}/{}", selected.name, selected.version);
|
||||
fetch_and_save_aur(selected)?;
|
||||
return Ok(());
|
||||
}
|
||||
println!("No exact match for '{package}'. Closest results:");
|
||||
for (i, r) in results.iter().take(5).enumerate() {
|
||||
println!(" {}. {}/{} — {}", i + 1, r.name, r.version, r.description);
|
||||
@@ -430,6 +451,11 @@ fn install_package(context: &AppContext, package: &str, force: bool) -> Result<(
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if noconfirm {
|
||||
fetch_and_save_aur(pkg)?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
println!("Would you like to fetch this package from AUR into ~/.cub/? [y/N]");
|
||||
|
||||
let mut answer = String::new();
|
||||
|
||||
Reference in New Issue
Block a user