cli: fix global -y flag conflicts in add-prj` and sync commands

`AddPrjArgs` had a local `-y` flag that conflicted with the global flag,
causing runtime panics. Removed the local field and updated callers to
use `global_yes` consistently.

The sync command now respects the global `-y` flag by accepting, you
guessed it, the `global_yes` parameter.

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I7b7c42fabbca0e363bd18a1d8b6b3bb76a6a6964
This commit is contained in:
raf 2026-02-27 22:26:38 +03:00
commit b0a594e892
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
3 changed files with 81 additions and 50 deletions

View file

@ -1,7 +1,6 @@
use std::{
collections::{HashMap, HashSet},
fs,
io::{self, Write},
path::{Path, PathBuf},
};
@ -22,6 +21,7 @@ enum SyncChange {
pub async fn execute(
args: SyncArgs,
global_yes: bool,
lockfile_path: &Path,
config_path: &Path,
) -> Result<()> {
@ -66,7 +66,11 @@ pub async fn execute(
for (file_path, _) in &additions {
spinner
.set_message(format!("Processing addition: {}", file_path.display()));
if prompt_user(&format!("Add {} to lockfile?", file_path.display()))? {
if crate::ui_utils::prompt_yes_no(
&format!("Add {} to lockfile?", file_path.display()),
false,
global_yes,
)? {
add_file_to_lockfile(&mut lockfile, file_path, &config).await?;
}
}
@ -87,7 +91,11 @@ pub async fn execute(
.or(project.pakku_id.as_deref())
.unwrap_or("unknown");
spinner.set_message(format!("Processing removal: {name}"));
if prompt_user(&format!("Remove {name} from lockfile?"))? {
if crate::ui_utils::prompt_yes_no(
&format!("Remove {name} from lockfile?"),
false,
global_yes,
)? {
lockfile
.remove_project(pakku_id)
.ok_or_else(|| PakkerError::ProjectNotFound(pakku_id.clone()))?;
@ -174,7 +182,7 @@ async fn add_file_to_lockfile(
_config: &Config,
) -> Result<()> {
// Try to identify the file by hash lookup
let _modrinth = ModrinthPlatform::new();
let modrinth = ModrinthPlatform::new();
let curseforge = CurseForgePlatform::new(None);
// Compute file hash
@ -186,7 +194,7 @@ async fn add_file_to_lockfile(
let hash = format!("{:x}", hasher.finalize());
// Try Modrinth first (SHA-1 hash)
if let Ok(Some(project)) = _modrinth.lookup_by_hash(&hash).await {
if let Ok(Some(project)) = modrinth.lookup_by_hash(&hash).await {
lockfile.add_project(project);
println!("✓ Added {} (from Modrinth)", file_path.display());
return Ok(());
@ -202,15 +210,3 @@ async fn add_file_to_lockfile(
println!("⚠ Could not identify {}, skipping", file_path.display());
Ok(())
}
fn prompt_user(message: &str) -> Result<bool> {
print!("{message} [y/N] ");
io::stdout().flush().map_err(PakkerError::IoError)?;
let mut input = String::new();
io::stdin()
.read_line(&mut input)
.map_err(PakkerError::IoError)?;
Ok(input.trim().eq_ignore_ascii_case("y"))
}