cli/commands: use create_all_platforms to reduce duplication in update cmd
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I00d3029de7c13a57cefb1b6eaae9f1606a6a6964
This commit is contained in:
parent
f4287de795
commit
0b5882b1e1
1 changed files with 10 additions and 15 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
use std::{collections::HashMap, path::Path};
|
use std::path::Path;
|
||||||
|
|
||||||
use indicatif::{ProgressBar, ProgressStyle};
|
use indicatif::{ProgressBar, ProgressStyle};
|
||||||
|
|
||||||
|
|
@ -6,15 +6,16 @@ use crate::{
|
||||||
cli::UpdateArgs,
|
cli::UpdateArgs,
|
||||||
error::{MultiError, PakkerError},
|
error::{MultiError, PakkerError},
|
||||||
model::{Config, LockFile, UpdateStrategy},
|
model::{Config, LockFile, UpdateStrategy},
|
||||||
platform::create_platform,
|
|
||||||
ui_utils::{prompt_select, prompt_typo_suggestion, prompt_yes_no},
|
ui_utils::{prompt_select, prompt_typo_suggestion, prompt_yes_no},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub async fn execute(
|
pub async fn execute(
|
||||||
args: UpdateArgs,
|
args: UpdateArgs,
|
||||||
|
global_yes: bool,
|
||||||
lockfile_path: &Path,
|
lockfile_path: &Path,
|
||||||
config_path: &Path,
|
config_path: &Path,
|
||||||
) -> Result<(), PakkerError> {
|
) -> Result<(), PakkerError> {
|
||||||
|
let skip_prompts = global_yes;
|
||||||
// Load expects directory path, so get parent directory
|
// Load expects directory path, so get parent directory
|
||||||
let lockfile_dir = lockfile_path.parent().unwrap_or(Path::new("."));
|
let lockfile_dir = lockfile_path.parent().unwrap_or(Path::new("."));
|
||||||
let config_dir = config_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)?;
|
let _config = Config::load(config_dir)?;
|
||||||
|
|
||||||
// Create platforms
|
// Create platforms
|
||||||
let mut platforms = HashMap::new();
|
let platforms = super::add::create_all_platforms()?;
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collect all known project identifiers for typo suggestions
|
// Collect all known project identifiers for typo suggestions
|
||||||
let all_slugs: Vec<String> = lockfile
|
let all_slugs: Vec<String> = lockfile
|
||||||
|
|
@ -63,7 +56,8 @@ pub async fn execute(
|
||||||
indices.push(idx);
|
indices.push(idx);
|
||||||
} else {
|
} else {
|
||||||
// Try typo suggestion
|
// 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
|
&& let Some((idx, _)) = lockfile
|
||||||
.projects
|
.projects
|
||||||
.iter()
|
.iter()
|
||||||
|
|
@ -159,17 +153,18 @@ pub async fn execute(
|
||||||
} else {
|
} else {
|
||||||
// Interactive confirmation and version selection if not using --yes
|
// Interactive confirmation and version selection if not using --yes
|
||||||
// flag
|
// flag
|
||||||
let mut should_update = args.yes || args.all;
|
let mut should_update = skip_prompts || args.all;
|
||||||
let mut selected_idx: Option<usize> = None;
|
let mut selected_idx: Option<usize> = None;
|
||||||
|
|
||||||
if !args.yes && !args.all {
|
if !skip_prompts && !args.all {
|
||||||
pb.suspend(|| {
|
pb.suspend(|| {
|
||||||
// First, confirm the update
|
// First, confirm the update
|
||||||
let prompt_msg = format!(
|
let prompt_msg = format!(
|
||||||
"Update '{project_name}' from {old_file_name} to \
|
"Update '{project_name}' from {old_file_name} to \
|
||||||
{new_file_name}?"
|
{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 confirmed and multiple versions available, offer selection
|
||||||
if should_update && updated_project.files.len() > 1 {
|
if should_update && updated_project.files.len() > 1 {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue