cli/commands: update all commands to use global_yes parameter

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I4d95a425f2bed75aed1b5233adf1a3646a6a6964
This commit is contained in:
raf 2026-02-28 23:40:42 +03:00
commit f2af2fbbe4
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
6 changed files with 39 additions and 17 deletions

View file

@ -57,9 +57,11 @@ use crate::{cli::AddArgs, model::fork::LocalConfig};
pub async fn execute(
args: AddArgs,
global_yes: bool,
lockfile_path: &Path,
config_path: &Path,
) -> Result<()> {
let skip_prompts = global_yes;
log::info!("Adding projects: {:?}", args.inputs);
// Load lockfile
@ -187,9 +189,9 @@ pub async fn execute(
}
// Prompt for confirmation unless --yes flag is set
if !args.yes {
if !skip_prompts {
let prompt_msg = format!("Add project '{}'?", project.get_name());
if !crate::ui_utils::prompt_yes_no(&prompt_msg, true)? {
if !crate::ui_utils::prompt_yes_no(&prompt_msg, true, skip_prompts)? {
log::info!("Skipping project: {}", project.get_name());
continue;
}
@ -213,13 +215,14 @@ pub async fn execute(
&& !all_new_projects.iter().any(|p| p.pakku_id == dep.pakku_id)
{
// Prompt user for confirmation unless --yes flag is set
if !args.yes {
if !skip_prompts {
let prompt_msg = format!(
"Add dependency '{}' required by '{}'?",
dep.get_name(),
project.get_name()
);
if !crate::ui_utils::prompt_yes_no(&prompt_msg, true)? {
if !crate::ui_utils::prompt_yes_no(&prompt_msg, true, skip_prompts)?
{
log::info!("Skipping dependency: {}", dep.get_name());
continue;
}

View file

@ -232,7 +232,7 @@ pub async fn execute(
"Project '{existing_name}' already exists. Replace with \
'{project_name}'?"
);
if !crate::ui_utils::prompt_yes_no(&prompt_msg, false)? {
if !crate::ui_utils::prompt_yes_no(&prompt_msg, false, yes)? {
log::info!("Operation cancelled by user");
return Ok(());
}
@ -244,7 +244,7 @@ pub async fn execute(
} else {
if !yes {
let prompt_msg = format!("Add project '{project_name}'?");
if !crate::ui_utils::prompt_yes_no(&prompt_msg, true)? {
if !crate::ui_utils::prompt_yes_no(&prompt_msg, true, yes)? {
log::info!("Operation cancelled by user");
return Ok(());
}
@ -283,7 +283,7 @@ pub async fn execute(
if !yes {
let prompt_msg =
format!("Add dependency '{dep_name}' required by '{project_name}'?");
if !crate::ui_utils::prompt_yes_no(&prompt_msg, true)? {
if !crate::ui_utils::prompt_yes_no(&prompt_msg, true, yes)? {
log::info!("Skipping dependency: {dep_name}");
continue;
}

View file

@ -32,7 +32,7 @@ pub fn execute(
// Find the project in lockfile to get its pakku_id
// Try multiple lookup strategies: pakku_id first, then slug, then name
let found_project = lockfile
.find_project(&project)
.get_project(&project)
.or_else(|| {
// Try to find by slug on any platform
lockfile

View file

@ -9,9 +9,11 @@ use crate::{
pub async fn execute(
args: ImportArgs,
global_yes: bool,
lockfile_path: &Path,
config_path: &Path,
) -> Result<()> {
let skip_prompts = global_yes;
log::info!("Importing modpack from {}", args.file);
log::info!(
"Dependency resolution: {}",
@ -27,7 +29,7 @@ pub async fn execute(
}
// Check if lockfile or config already exist
if (lockfile_path.exists() || config_path.exists()) && !args.yes {
if (lockfile_path.exists() || config_path.exists()) && !skip_prompts {
let msg = if lockfile_path.exists() && config_path.exists() {
"Both pakku-lock.json and pakku.json exist. Importing will overwrite \
them. Continue?"
@ -37,7 +39,7 @@ pub async fn execute(
"pakku.json exists. Importing will overwrite it. Continue?"
};
if !prompt_yes_no(msg, false)? {
if !prompt_yes_no(msg, false, skip_prompts)? {
log::info!("Import cancelled by user");
return Ok(());
}
@ -146,6 +148,7 @@ async fn import_modrinth(
if let Err(e) = project.select_file(
&lockfile.mc_versions,
std::slice::from_ref(&loader.0),
None, // Use default (1 file) during import
) {
log::warn!(
"Failed to select file for {}: {}",
@ -185,6 +188,7 @@ async fn import_modrinth(
projects: None,
export_profiles: None,
export_server_side_projects_to_client: None,
file_count_preference: None,
};
// Save files using provided paths
@ -314,6 +318,7 @@ async fn import_curseforge(
if let Err(e) = project.select_file(
&lockfile.mc_versions,
&loaders.keys().cloned().collect::<Vec<_>>(),
None, // Use default (1 file) during import
) {
log::warn!(
"Failed to select file for {}: {}",
@ -328,6 +333,7 @@ async fn import_curseforge(
if let Err(e) = project.select_file(
&lockfile.mc_versions,
&loaders.keys().cloned().collect::<Vec<_>>(),
None, // Use default (1 file) during import
) {
log::warn!(
"Failed to select file for {}: {}",
@ -368,6 +374,7 @@ async fn import_curseforge(
projects: None,
export_profiles: None,
export_server_side_projects_to_client: None,
file_count_preference: None,
};
// Save files using provided paths

View file

@ -14,9 +14,12 @@ use crate::{
pub async fn execute(
args: InitArgs,
global_yes: bool,
lockfile_path: &Path,
config_path: &Path,
) -> Result<(), PakkerError> {
let skip_prompts = global_yes;
if lockfile_path.exists() {
return Err(PakkerError::AlreadyExists(
"Lock file already exists".into(),
@ -24,7 +27,7 @@ pub async fn execute(
}
// Interactive mode: prompt for values not provided via CLI and --yes not set
let is_interactive = !args.yes && args.name.is_none();
let is_interactive = !skip_prompts && args.name.is_none();
// Get modpack name
let name = if let Some(name) = args.name.clone() {
@ -137,6 +140,7 @@ pub async fn execute(
projects: None,
export_profiles: None,
export_server_side_projects_to_client: None,
file_count_preference: None,
};
let config_dir = config_path.parent().unwrap_or(Path::new("."));
@ -164,9 +168,13 @@ pub async fn execute(
if !has_cf_key {
println!();
if prompt_yes_no("Would you like to set up CurseForge API key now?", true)
.map_err(|e| PakkerError::InvalidInput(e.to_string()))?
&& let Ok(Some(api_key)) = prompt_curseforge_api_key()
if prompt_yes_no(
"Would you like to set up CurseForge API key now?",
true,
skip_prompts,
)
.map_err(|e| PakkerError::InvalidInput(e.to_string()))?
&& let Ok(Some(api_key)) = prompt_curseforge_api_key(skip_prompts)
{
// Save to credentials file
let creds_path = std::env::var("HOME").map_or_else(

View file

@ -9,9 +9,11 @@ use crate::{
pub async fn execute(
args: RmArgs,
global_yes: bool,
lockfile_path: &Path,
_config_path: &Path,
) -> Result<()> {
let skip_prompts = global_yes;
// Load expects directory path, so get parent directory
let lockfile_dir = lockfile_path.parent().unwrap_or(Path::new("."));
let mut lockfile = LockFile::load(lockfile_dir)?;
@ -79,7 +81,9 @@ pub async fn execute(
resolved_inputs.push(input.clone());
} else if !args.all {
// 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)
{
log::info!("Using suggested project: {suggestion}");
resolved_inputs.push(suggestion);
} else {
@ -111,13 +115,13 @@ pub async fn execute(
// Ask for confirmation unless --yes flag is provided or --all with no
// projects
if !args.yes {
if !skip_prompts {
println!("The following projects will be removed:");
for name in &projects_to_remove {
println!(" - {name}");
}
if !prompt_yes_no("Do you want to continue?", false)? {
if !prompt_yes_no("Do you want to continue?", false, skip_prompts)? {
println!("Removal cancelled.");
return Ok(());
}