feat: optimize info
This commit is contained in:
@@ -26,9 +26,10 @@ pub struct CmdInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn info(cmd_info: CmdInfo) -> XResult<()> {
|
pub fn info(cmd_info: CmdInfo) -> XResult<()> {
|
||||||
|
let config = TinyEncryptConfig::load(TINY_ENC_CONFIG_FILE).ok();
|
||||||
for (i, path) in cmd_info.paths.iter().enumerate() {
|
for (i, path) in cmd_info.paths.iter().enumerate() {
|
||||||
if i > 0 { println!("{}", "-".repeat(88)); }
|
if i > 0 { println!("{}", "-".repeat(88)); }
|
||||||
if let Err(e) = info_single(path, &cmd_info) {
|
if let Err(e) = info_single(path, &cmd_info, &config) {
|
||||||
failure!("Parse Tiny Encrypt file info failed: {}", e);
|
failure!("Parse Tiny Encrypt file info failed: {}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,13 +37,12 @@ pub fn info(cmd_info: CmdInfo) -> XResult<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn info_single(path: &PathBuf, cmd_info: &CmdInfo) -> XResult<()> {
|
pub fn info_single(path: &PathBuf, cmd_info: &CmdInfo, config: &Option<TinyEncryptConfig>) -> XResult<()> {
|
||||||
let path_display = format!("{}", path.display());
|
let path_display = format!("{}", path.display());
|
||||||
if !path_display.ends_with(TINY_ENC_FILE_EXT) {
|
if !path_display.ends_with(TINY_ENC_FILE_EXT) {
|
||||||
return simple_error!("Not a Tiny Encrypt file: {}", path_display);
|
return simple_error!("Not a Tiny Encrypt file: {}", path_display);
|
||||||
}
|
}
|
||||||
|
|
||||||
let config = TinyEncryptConfig::load(TINY_ENC_CONFIG_FILE).ok();
|
|
||||||
let mut file_in = opt_result!(File::open(path), "Open file: {} failed: {}", &path_display);
|
let mut file_in = opt_result!(File::open(path), "Open file: {} failed: {}", &path_display);
|
||||||
let file_in_len = file_in.metadata().map(|m| m.len()).unwrap_or(0);
|
let file_in_len = file_in.metadata().map(|m| m.len()).unwrap_or(0);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user