From 2c3c59e882b1a01627d2211f1cc74e5c9a70cae7 Mon Sep 17 00:00:00 2001 From: Cno Date: Sun, 11 Aug 2024 23:07:54 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E4=BC=98=E5=8C=96=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entrances/install.rs | 27 +++++++++++++++------------ src/entrances/uninstall.rs | 9 +++++---- src/main.rs | 11 +++++------ 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/entrances/install.rs b/src/entrances/install.rs index 965c2f12..e23413ac 100644 --- a/src/entrances/install.rs +++ b/src/entrances/install.rs @@ -23,7 +23,10 @@ use crate::{ }, }; -pub fn install_using_package(source_file: &String, verify_signature: bool) -> Result<()> { +pub fn install_using_package( + source_file: &String, + verify_signature: bool, +) -> Result<(String, String)> { log!("Info:Preparing to install with package '{source_file}'"); // 解包 @@ -66,8 +69,8 @@ pub fn install_using_package(source_file: &String, verify_signature: bool) -> Re name = package.name, ver = diff.version, ); - update_using_package(source_file, verify_signature)?; - return Ok(()); + let res = update_using_package(source_file, verify_signature)?; + return Ok((res.scope, res.name)); } // 解析最终安装位置 @@ -117,22 +120,22 @@ pub fn install_using_package(source_file: &String, verify_signature: bool) -> Re } } // 执行一次 info - if let Err(e) = info(Some(software.scope.clone()), &package.name) { - return Err(anyhow!( + info(Some(software.scope.clone()), &package.name).map_err(|e| { + anyhow!( "Error:Validating failed : failed to get info of '{scope}/{name}' : {e}", scope = software.scope, name = package.name - )); - } + ) + })?; log_ok_last!("Info:Validating setup..."); // 清理临时文件夹 clean_temp(source_file)?; - Ok(()) + Ok((software.scope, package.name)) } -pub fn install_using_url(url: &str, verify_signature: bool) -> Result<()> { +pub fn install_using_url(url: &str, verify_signature: bool) -> Result<(String, String)> { // 下载文件到临时目录 let p = download_nep(url)?; @@ -143,7 +146,7 @@ pub fn install_using_url(url: &str, verify_signature: bool) -> Result<()> { pub fn install_using_package_matcher( matcher: PackageMatcher, verify_signature: bool, -) -> Result<()> { +) -> Result<(String, String)> { // 查找 scope 并使用 scope 更新纠正大小写 let (scope, package_name) = find_scope_with_name(&matcher.name, matcher.scope.clone())?; // 检查对应包名有没有被安装过 @@ -153,8 +156,8 @@ pub fn install_using_package_matcher( name = package_name, ver = diff.version, ); - update_using_package_matcher(matcher, verify_signature)?; - return Ok(()); + let res = update_using_package_matcher(matcher, verify_signature)?; + return Ok((res.scope, res.name)); } // 解析 url let (url, target_release) = get_url_with_version_req(matcher)?; diff --git a/src/entrances/uninstall.rs b/src/entrances/uninstall.rs index 0f88d1ea..d1c342d8 100644 --- a/src/entrances/uninstall.rs +++ b/src/entrances/uninstall.rs @@ -33,7 +33,7 @@ fn get_manifest(flow: Vec) -> Vec { manifest } -pub fn uninstall(scope: Option, package_name: &String) -> Result<()> { +pub fn uninstall(scope: Option, package_name: &String) -> Result<(String, String)> { log!("Info:Preparing to uninstall '{package_name}'"); // 查找 scope 并使用 scope 更新纠正大小写 @@ -50,11 +50,12 @@ pub fn uninstall(scope: Option, package_name: &String) -> Result<()> { if let Err(e) = installed_validator(&app_str) { // 简单的删除目录 log!("Warning:Incomplete folder found, simply perform a deletion : {e}"); - return remove_dir_all(&app_str).map_err(|e| { + remove_dir_all(&app_str).map_err(|e| { anyhow!( "Warning:Can't clean the directory, please delete '{app_str}' manually later : {e}" ) - }); + })?; + return Ok((scope, package_name)); } // 读入 package.toml @@ -154,7 +155,7 @@ pub fn uninstall(scope: Option, package_name: &String) -> Result<()> { log_ok_last!("Info:Cleaning..."); - Ok(()) + Ok((scope, package_name)) } #[test] diff --git a/src/main.rs b/src/main.rs index e8956e24..2da6a214 100644 --- a/src/main.rs +++ b/src/main.rs @@ -61,7 +61,9 @@ fn router(action: Action) -> Result { install_using_package(&source_file, verify_signature) } }; - res.map(|_| format!("Success:Package '{package}' installed successfully")) + res.map(|(scope, name)| { + format!("Success:Package '{scope}/{name}' installed successfully") + }) } Action::Update { package } => { if let Some(package) = package { @@ -92,11 +94,8 @@ fn router(action: Action) -> Result { } Action::Uninstall { package_matcher } => { let parse_res = PackageMatcher::parse(&package_matcher, true, true)?; - uninstall(parse_res.scope, &parse_res.name).map(|_| { - format!( - "Success:Package '{name}' uninstalled successfully", - name = parse_res.name - ) + uninstall(parse_res.scope, &parse_res.name).map(|(scope, name)| { + format!("Success:Package '{scope}/{name}' uninstalled successfully") }) } Action::Search { keyword, regex } => {