From cbdcd101c11271765940270c923e8944dbba829f Mon Sep 17 00:00:00 2001 From: Vasilito Date: Fri, 8 May 2026 07:32:38 +0100 Subject: [PATCH] fix: cubl exact-match AUR search, numbered ambiguity menu, PKGBUILD-not-found handling --- .../system/cub/source/cub-cli/src/main.rs | 50 +++++++++++++++++-- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/local/recipes/system/cub/source/cub-cli/src/main.rs b/local/recipes/system/cub/source/cub-cli/src/main.rs index 272bb3683..3e39d13dc 100644 --- a/local/recipes/system/cub/source/cub-cli/src/main.rs +++ b/local/recipes/system/cub/source/cub-cli/src/main.rs @@ -372,20 +372,38 @@ fn install_package(context: &AppContext, package: &str) -> Result<(), Box 1 { + 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); + } + println!("Enter number to select (or 0 to skip): "); + let mut choice = String::new(); + io::stdin().read_line(&mut choice)?; + if let Ok(n) = choice.trim().parse::() { + if n > 0 && n <= results.len().min(5) { + let selected = &results[n - 1]; + println!("Selected: {}/{}", selected.name, selected.version); + fetch_and_save_aur(selected)?; + } + } + return Ok(()); + } + println!("Found: {}/{} — {}", pkg.name, pkg.version, pkg.description); println!("Would you like to fetch this package from AUR into ~/.cub/? [y/N]"); let mut answer = String::new(); io::stdin().read_line(&mut answer)?; if answer.trim().to_ascii_lowercase().starts_with('y') { - fetch_aur_to_store(&pkg.name)?; - println!("Recipe saved to ~/.cub/recipes/{}/", pkg.name); - println!("Build with: cubl -B ~/.cub/recipes/{}/", pkg.name); + fetch_and_save_aur(pkg)?; } return Ok(()); } @@ -697,6 +715,13 @@ fn fetch_aur_to_store(package: &str) -> Result<(), Box> { } let pkgbuild_path = clone_dir.join("PKGBUILD"); + if !pkgbuild_path.exists() { + return Err(Box::new(CubError::PackageNotFound(format!( + "AUR repository cloned but PKGBUILD not found at {}. The package may be a split package or empty.", + pkgbuild_path.display() + )))); + } + let pkgbuild_content = fs::read_to_string(&pkgbuild_path)?; let conversion = pkgbuild::convert_pkgbuild(&pkgbuild_content)?; @@ -707,6 +732,21 @@ fn fetch_aur_to_store(package: &str) -> Result<(), Box> { Ok(()) } +fn fetch_and_save_aur(pkg: &AurPackage) -> Result<(), Box> { + match fetch_aur_to_store(&pkg.name) { + Ok(()) => { + println!("Recipe saved to ~/.cub/recipes/{}/", pkg.name); + println!("Build with: cubl -B ~/.cub/recipes/{}/", pkg.name); + Ok(()) + } + Err(e) => { + eprintln!("Failed to fetch {name}: {e}", name = pkg.name); + eprintln!("Try manual import: cubl --import-aur {name}", name = pkg.name); + Err(e) + } + } +} + fn fetch_bur_recipe(package: &str) -> Result<(), Box> { let source_dir = ensure_bur_package_dir(package)?; let destination = env::current_dir()?.join(package);