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:
parent
a89184a358
commit
f2af2fbbe4
6 changed files with 39 additions and 17 deletions
|
|
@ -57,9 +57,11 @@ use crate::{cli::AddArgs, model::fork::LocalConfig};
|
||||||
|
|
||||||
pub async fn execute(
|
pub async fn execute(
|
||||||
args: AddArgs,
|
args: AddArgs,
|
||||||
|
global_yes: bool,
|
||||||
lockfile_path: &Path,
|
lockfile_path: &Path,
|
||||||
config_path: &Path,
|
config_path: &Path,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let skip_prompts = global_yes;
|
||||||
log::info!("Adding projects: {:?}", args.inputs);
|
log::info!("Adding projects: {:?}", args.inputs);
|
||||||
|
|
||||||
// Load lockfile
|
// Load lockfile
|
||||||
|
|
@ -187,9 +189,9 @@ pub async fn execute(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prompt for confirmation unless --yes flag is set
|
// Prompt for confirmation unless --yes flag is set
|
||||||
if !args.yes {
|
if !skip_prompts {
|
||||||
let prompt_msg = format!("Add project '{}'?", project.get_name());
|
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());
|
log::info!("Skipping project: {}", project.get_name());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -213,13 +215,14 @@ pub async fn execute(
|
||||||
&& !all_new_projects.iter().any(|p| p.pakku_id == dep.pakku_id)
|
&& !all_new_projects.iter().any(|p| p.pakku_id == dep.pakku_id)
|
||||||
{
|
{
|
||||||
// Prompt user for confirmation unless --yes flag is set
|
// Prompt user for confirmation unless --yes flag is set
|
||||||
if !args.yes {
|
if !skip_prompts {
|
||||||
let prompt_msg = format!(
|
let prompt_msg = format!(
|
||||||
"Add dependency '{}' required by '{}'?",
|
"Add dependency '{}' required by '{}'?",
|
||||||
dep.get_name(),
|
dep.get_name(),
|
||||||
project.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());
|
log::info!("Skipping dependency: {}", dep.get_name());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -232,7 +232,7 @@ pub async fn execute(
|
||||||
"Project '{existing_name}' already exists. Replace with \
|
"Project '{existing_name}' already exists. Replace with \
|
||||||
'{project_name}'?"
|
'{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");
|
log::info!("Operation cancelled by user");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
@ -244,7 +244,7 @@ pub async fn execute(
|
||||||
} else {
|
} else {
|
||||||
if !yes {
|
if !yes {
|
||||||
let prompt_msg = format!("Add project '{project_name}'?");
|
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");
|
log::info!("Operation cancelled by user");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
@ -283,7 +283,7 @@ pub async fn execute(
|
||||||
if !yes {
|
if !yes {
|
||||||
let prompt_msg =
|
let prompt_msg =
|
||||||
format!("Add dependency '{dep_name}' required by '{project_name}'?");
|
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}");
|
log::info!("Skipping dependency: {dep_name}");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ pub fn execute(
|
||||||
// Find the project in lockfile to get its pakku_id
|
// Find the project in lockfile to get its pakku_id
|
||||||
// Try multiple lookup strategies: pakku_id first, then slug, then name
|
// Try multiple lookup strategies: pakku_id first, then slug, then name
|
||||||
let found_project = lockfile
|
let found_project = lockfile
|
||||||
.find_project(&project)
|
.get_project(&project)
|
||||||
.or_else(|| {
|
.or_else(|| {
|
||||||
// Try to find by slug on any platform
|
// Try to find by slug on any platform
|
||||||
lockfile
|
lockfile
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,11 @@ use crate::{
|
||||||
|
|
||||||
pub async fn execute(
|
pub async fn execute(
|
||||||
args: ImportArgs,
|
args: ImportArgs,
|
||||||
|
global_yes: bool,
|
||||||
lockfile_path: &Path,
|
lockfile_path: &Path,
|
||||||
config_path: &Path,
|
config_path: &Path,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let skip_prompts = global_yes;
|
||||||
log::info!("Importing modpack from {}", args.file);
|
log::info!("Importing modpack from {}", args.file);
|
||||||
log::info!(
|
log::info!(
|
||||||
"Dependency resolution: {}",
|
"Dependency resolution: {}",
|
||||||
|
|
@ -27,7 +29,7 @@ pub async fn execute(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if lockfile or config already exist
|
// 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() {
|
let msg = if lockfile_path.exists() && config_path.exists() {
|
||||||
"Both pakku-lock.json and pakku.json exist. Importing will overwrite \
|
"Both pakku-lock.json and pakku.json exist. Importing will overwrite \
|
||||||
them. Continue?"
|
them. Continue?"
|
||||||
|
|
@ -37,7 +39,7 @@ pub async fn execute(
|
||||||
"pakku.json exists. Importing will overwrite it. Continue?"
|
"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");
|
log::info!("Import cancelled by user");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
@ -146,6 +148,7 @@ async fn import_modrinth(
|
||||||
if let Err(e) = project.select_file(
|
if let Err(e) = project.select_file(
|
||||||
&lockfile.mc_versions,
|
&lockfile.mc_versions,
|
||||||
std::slice::from_ref(&loader.0),
|
std::slice::from_ref(&loader.0),
|
||||||
|
None, // Use default (1 file) during import
|
||||||
) {
|
) {
|
||||||
log::warn!(
|
log::warn!(
|
||||||
"Failed to select file for {}: {}",
|
"Failed to select file for {}: {}",
|
||||||
|
|
@ -185,6 +188,7 @@ async fn import_modrinth(
|
||||||
projects: None,
|
projects: None,
|
||||||
export_profiles: None,
|
export_profiles: None,
|
||||||
export_server_side_projects_to_client: None,
|
export_server_side_projects_to_client: None,
|
||||||
|
file_count_preference: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Save files using provided paths
|
// Save files using provided paths
|
||||||
|
|
@ -314,6 +318,7 @@ async fn import_curseforge(
|
||||||
if let Err(e) = project.select_file(
|
if let Err(e) = project.select_file(
|
||||||
&lockfile.mc_versions,
|
&lockfile.mc_versions,
|
||||||
&loaders.keys().cloned().collect::<Vec<_>>(),
|
&loaders.keys().cloned().collect::<Vec<_>>(),
|
||||||
|
None, // Use default (1 file) during import
|
||||||
) {
|
) {
|
||||||
log::warn!(
|
log::warn!(
|
||||||
"Failed to select file for {}: {}",
|
"Failed to select file for {}: {}",
|
||||||
|
|
@ -328,6 +333,7 @@ async fn import_curseforge(
|
||||||
if let Err(e) = project.select_file(
|
if let Err(e) = project.select_file(
|
||||||
&lockfile.mc_versions,
|
&lockfile.mc_versions,
|
||||||
&loaders.keys().cloned().collect::<Vec<_>>(),
|
&loaders.keys().cloned().collect::<Vec<_>>(),
|
||||||
|
None, // Use default (1 file) during import
|
||||||
) {
|
) {
|
||||||
log::warn!(
|
log::warn!(
|
||||||
"Failed to select file for {}: {}",
|
"Failed to select file for {}: {}",
|
||||||
|
|
@ -368,6 +374,7 @@ async fn import_curseforge(
|
||||||
projects: None,
|
projects: None,
|
||||||
export_profiles: None,
|
export_profiles: None,
|
||||||
export_server_side_projects_to_client: None,
|
export_server_side_projects_to_client: None,
|
||||||
|
file_count_preference: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Save files using provided paths
|
// Save files using provided paths
|
||||||
|
|
|
||||||
|
|
@ -14,9 +14,12 @@ use crate::{
|
||||||
|
|
||||||
pub async fn execute(
|
pub async fn execute(
|
||||||
args: InitArgs,
|
args: InitArgs,
|
||||||
|
global_yes: bool,
|
||||||
lockfile_path: &Path,
|
lockfile_path: &Path,
|
||||||
config_path: &Path,
|
config_path: &Path,
|
||||||
) -> Result<(), PakkerError> {
|
) -> Result<(), PakkerError> {
|
||||||
|
let skip_prompts = global_yes;
|
||||||
|
|
||||||
if lockfile_path.exists() {
|
if lockfile_path.exists() {
|
||||||
return Err(PakkerError::AlreadyExists(
|
return Err(PakkerError::AlreadyExists(
|
||||||
"Lock file already exists".into(),
|
"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
|
// 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
|
// Get modpack name
|
||||||
let name = if let Some(name) = args.name.clone() {
|
let name = if let Some(name) = args.name.clone() {
|
||||||
|
|
@ -137,6 +140,7 @@ pub async fn execute(
|
||||||
projects: None,
|
projects: None,
|
||||||
export_profiles: None,
|
export_profiles: None,
|
||||||
export_server_side_projects_to_client: None,
|
export_server_side_projects_to_client: None,
|
||||||
|
file_count_preference: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let config_dir = config_path.parent().unwrap_or(Path::new("."));
|
let config_dir = config_path.parent().unwrap_or(Path::new("."));
|
||||||
|
|
@ -164,9 +168,13 @@ pub async fn execute(
|
||||||
|
|
||||||
if !has_cf_key {
|
if !has_cf_key {
|
||||||
println!();
|
println!();
|
||||||
if prompt_yes_no("Would you like to set up CurseForge API key now?", true)
|
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()))?
|
.map_err(|e| PakkerError::InvalidInput(e.to_string()))?
|
||||||
&& let Ok(Some(api_key)) = prompt_curseforge_api_key()
|
&& let Ok(Some(api_key)) = prompt_curseforge_api_key(skip_prompts)
|
||||||
{
|
{
|
||||||
// Save to credentials file
|
// Save to credentials file
|
||||||
let creds_path = std::env::var("HOME").map_or_else(
|
let creds_path = std::env::var("HOME").map_or_else(
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,11 @@ use crate::{
|
||||||
|
|
||||||
pub async fn execute(
|
pub async fn execute(
|
||||||
args: RmArgs,
|
args: RmArgs,
|
||||||
|
global_yes: bool,
|
||||||
lockfile_path: &Path,
|
lockfile_path: &Path,
|
||||||
_config_path: &Path,
|
_config_path: &Path,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
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 mut lockfile = LockFile::load(lockfile_dir)?;
|
let mut lockfile = LockFile::load(lockfile_dir)?;
|
||||||
|
|
@ -79,7 +81,9 @@ pub async fn execute(
|
||||||
resolved_inputs.push(input.clone());
|
resolved_inputs.push(input.clone());
|
||||||
} else if !args.all {
|
} else if !args.all {
|
||||||
// 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)
|
||||||
|
{
|
||||||
log::info!("Using suggested project: {suggestion}");
|
log::info!("Using suggested project: {suggestion}");
|
||||||
resolved_inputs.push(suggestion);
|
resolved_inputs.push(suggestion);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -111,13 +115,13 @@ pub async fn execute(
|
||||||
|
|
||||||
// Ask for confirmation unless --yes flag is provided or --all with no
|
// Ask for confirmation unless --yes flag is provided or --all with no
|
||||||
// projects
|
// projects
|
||||||
if !args.yes {
|
if !skip_prompts {
|
||||||
println!("The following projects will be removed:");
|
println!("The following projects will be removed:");
|
||||||
for name in &projects_to_remove {
|
for name in &projects_to_remove {
|
||||||
println!(" - {name}");
|
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.");
|
println!("Removal cancelled.");
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue