From 0b5882b1e1a1bd541e28dddd71da980e979dc388 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sat, 28 Feb 2026 23:09:34 +0300 Subject: [PATCH] cli/commands: use `create_all_platforms` to reduce duplication in update cmd Signed-off-by: NotAShelf Change-Id: I00d3029de7c13a57cefb1b6eaae9f1606a6a6964 --- src/cli/commands/update.rs | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/cli/commands/update.rs b/src/cli/commands/update.rs index f33caf2..785219b 100644 --- a/src/cli/commands/update.rs +++ b/src/cli/commands/update.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, path::Path}; +use std::path::Path; use indicatif::{ProgressBar, ProgressStyle}; @@ -6,15 +6,16 @@ use crate::{ cli::UpdateArgs, error::{MultiError, PakkerError}, model::{Config, LockFile, UpdateStrategy}, - platform::create_platform, ui_utils::{prompt_select, prompt_typo_suggestion, prompt_yes_no}, }; pub async fn execute( args: UpdateArgs, + global_yes: bool, lockfile_path: &Path, config_path: &Path, ) -> Result<(), PakkerError> { + let skip_prompts = global_yes; // Load expects directory path, so get parent directory let lockfile_dir = lockfile_path.parent().unwrap_or(Path::new(".")); let config_dir = config_path.parent().unwrap_or(Path::new(".")); @@ -23,15 +24,7 @@ pub async fn execute( let _config = Config::load(config_dir)?; // Create platforms - let mut platforms = HashMap::new(); - if let Ok(platform) = create_platform("modrinth", None) { - platforms.insert("modrinth".to_string(), platform); - } - if let Ok(platform) = - create_platform("curseforge", std::env::var("CURSEFORGE_API_KEY").ok()) - { - platforms.insert("curseforge".to_string(), platform); - } + let platforms = super::add::create_all_platforms()?; // Collect all known project identifiers for typo suggestions let all_slugs: Vec = lockfile @@ -63,7 +56,8 @@ pub async fn execute( indices.push(idx); } else { // Try typo suggestion - if let Ok(Some(suggestion)) = prompt_typo_suggestion(input, &all_slugs) + if let Ok(Some(suggestion)) = + prompt_typo_suggestion(input, &all_slugs, skip_prompts) && let Some((idx, _)) = lockfile .projects .iter() @@ -159,17 +153,18 @@ pub async fn execute( } else { // Interactive confirmation and version selection if not using --yes // flag - let mut should_update = args.yes || args.all; + let mut should_update = skip_prompts || args.all; let mut selected_idx: Option = None; - if !args.yes && !args.all { + if !skip_prompts && !args.all { pb.suspend(|| { // First, confirm the update let prompt_msg = format!( "Update '{project_name}' from {old_file_name} to \ {new_file_name}?" ); - should_update = prompt_yes_no(&prompt_msg, true).unwrap_or(false); + should_update = + prompt_yes_no(&prompt_msg, true, skip_prompts).unwrap_or(false); // If confirmed and multiple versions available, offer selection if should_update && updated_project.files.len() > 1 {