diff --git a/CHANGELOG.md b/CHANGELOG.md index e844f5c..2ca64b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Change Log +## [unreleased] + +### Added + +- Added manual select fallback if assets matching failed. + +### Fixed + +- Fixed extracting plugin zip file with backslashes in the path. +- Ignore version when importing plugin. + ## [0.6.0] ### Added diff --git a/README.md b/README.md index f383b57..a37efc5 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ cargo install --git https://github.com/8LWXpg/ptr.git ## Limitations +If you have any suggestions for these limitations, feel free to open an issue. + - This tool only supports plugins hosted on GitHub. - The plugin release must be a zip file with either `x64` or `arm64` in the file name. - The zip structure must be like this: diff --git a/src/util.rs b/src/util.rs index fe1dc47..705c817 100644 --- a/src/util.rs +++ b/src/util.rs @@ -1,4 +1,5 @@ use anyhow::{anyhow, bail, Result}; +use colored::Colorize; use reqwest::blocking::Client; use reqwest::header::{HeaderMap, ACCEPT, USER_AGENT}; use serde::Deserialize; @@ -88,11 +89,11 @@ pub fn gh_dl( } } - let asset = &res - .assets - .iter() - .find(|a| a.is_arch(arch)) - .ok_or(anyhow!("No asset found that contains '{}'", arch))?; + let assets = res.assets; + let asset = match assets.iter().find(|a| a.is_arch(arch)) { + Some(asset) => asset, + None => manual_select(&assets)?, + }; let (url, name) = (&asset.browser_download_url, &asset.name); let res = Client::new().get(url).send()?; @@ -106,6 +107,21 @@ pub fn gh_dl( Ok(tag) } +fn manual_select(assets: &[Assets]) -> Result<&Assets> { + if assets.len() == 1 { + return Ok(&assets[0]); + } + + println!("Fail to match assets, please select one:"); + for (i, asset) in assets.iter().enumerate() { + println!("{}: {}", i.to_string().bright_yellow(), asset.name); + } + let mut input = String::new(); + io::stdin().read_line(&mut input)?; + let index = input.trim().parse::()?; + assets.get(index).ok_or(anyhow!("Invalid index")) +} + fn extract_zip(zip_path: &Path, output_dir: &Path, root_name: &str) -> Result<()> { let file = File::open(zip_path)?; let mut archive = ZipArchive::new(file)?;