Skip to content

Commit

Permalink
chore: 优化打印
Browse files Browse the repository at this point in the history
  • Loading branch information
Cnotech committed Aug 11, 2024
1 parent 38e30d4 commit 2c3c59e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
27 changes: 15 additions & 12 deletions src/entrances/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}'");

// 解包
Expand Down Expand Up @@ -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));
}

// 解析最终安装位置
Expand Down Expand Up @@ -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)?;

Expand All @@ -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())?;
// 检查对应包名有没有被安装过
Expand All @@ -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)?;
Expand Down
9 changes: 5 additions & 4 deletions src/entrances/uninstall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn get_manifest(flow: Vec<WorkflowNode>) -> Vec<String> {
manifest
}

pub fn uninstall(scope: Option<String>, package_name: &String) -> Result<()> {
pub fn uninstall(scope: Option<String>, package_name: &String) -> Result<(String, String)> {
log!("Info:Preparing to uninstall '{package_name}'");

// 查找 scope 并使用 scope 更新纠正大小写
Expand All @@ -50,11 +50,12 @@ pub fn uninstall(scope: Option<String>, 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
Expand Down Expand Up @@ -154,7 +155,7 @@ pub fn uninstall(scope: Option<String>, package_name: &String) -> Result<()> {

log_ok_last!("Info:Cleaning...");

Ok(())
Ok((scope, package_name))
}

#[test]
Expand Down
11 changes: 5 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ fn router(action: Action) -> Result<String> {
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 {
Expand Down Expand Up @@ -92,11 +94,8 @@ fn router(action: Action) -> Result<String> {
}
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 } => {
Expand Down

0 comments on commit 2c3c59e

Please sign in to comment.