diff --git a/src/api.rs b/src/api.rs index 88871f5..8cfcb8e 100644 --- a/src/api.rs +++ b/src/api.rs @@ -13,6 +13,7 @@ pub struct SearchResponse { #[derive(Clone, Deserialize, Debug)] pub struct ModResult { pub mod_id: String, // TODO parse to `local-xxxxx` with regex + pub slug: String, // not in the API docs, but shows up in queries anyways pub project_type: Option, // NOTE this isn't in all search results? pub author: String, pub title: String, diff --git a/src/main.rs b/src/main.rs index f3e6e92..e50d948 100644 --- a/src/main.rs +++ b/src/main.rs @@ -175,8 +175,39 @@ async fn search_and_select( return Ok(vec![]); } + // TODO add a config file option to disable this + if let Some(first_result) = response.hits.first() { + if response.hits.len() == 1 { + println!("autoselecting only mod result"); + return Ok(vec![first_result.to_owned()]); + } + } + + // TODO add a config file option to disable this + for mod_info in response.hits.iter() { + if mod_info.slug == search_args.package_name { + println!("autoselecting mod result slug with exact match"); + return Ok(vec![mod_info.to_owned()]); + } + } + display_search_results(ctx, &response); - let selected = select_from_results(ctx, &response).await?; + let selected = loop { + let selected = select_from_results(ctx, &response).await?; + if selected.is_empty() { + use dialoguer::Confirm; + let mod_name = &search_args.package_name; + let prompt = format!("Really skip downloading {}?", mod_name); + let confirm = Confirm::new().with_prompt(prompt).interact()?; + if !confirm { + println!("Skipping updating {}...", mod_name); + } else { + continue; + } + } + + break selected; + }; Ok(selected) } @@ -266,30 +297,7 @@ async fn cmd_update(ctx: &AppContext, instance_dir: Option) -> anyhow:: version: Some(vec![hopfile.version.to_owned()]), }; - let response = search_mods(ctx, &search_args).await?; - - if response.hits.is_empty() { - error!("No results for {}; skipping update...", name); - continue; - } - - display_search_results(ctx, &response); - let selected = loop { - let selected = select_from_results(ctx, &response).await?; - if selected.is_empty() { - use dialoguer::Confirm; - let prompt = format!("Really skip updating {}?", name); - let confirm = Confirm::new().with_prompt(prompt).interact()?; - if !confirm { - println!("Skipping updating {}...", name); - } else { - continue; - } - } - - break selected; - }; - + let selected = search_and_select(ctx, &search_args).await?; // TODO update Hopfile.toml with specific versions using toml_edit crate download_mods(ctx, Some(&instance_dir), &target_versions, &selected).await?; }