feat: update info
This commit is contained in:
@@ -3,14 +3,19 @@ use std::fs::File;
|
||||
use std::ops::Add;
|
||||
use std::path::PathBuf;
|
||||
use std::time::{Duration, SystemTime};
|
||||
use rust_util::{information, opt_result, simple_error, XResult};
|
||||
use rust_util::{information, opt_result, simple_error, success, XResult};
|
||||
use crate::file;
|
||||
|
||||
pub fn info(path: PathBuf) -> XResult<()> {
|
||||
pub fn info(path: PathBuf, raw_meta: bool) -> XResult<()> {
|
||||
let path_display = format!("{}", path.display());
|
||||
let mut file_in = opt_result!(File::open(path), "Open file: {} failed: {}", &path_display);
|
||||
let meta = opt_result!(file::read_tiny_encrypt_meta(&mut file_in), "Read file: {}, failed: {}", &path_display);
|
||||
|
||||
if raw_meta {
|
||||
success!("Meta data:\n{}", serde_json::to_string_pretty(&meta).expect("SHOULD NOT HAPPEN"));
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut infos = vec![];
|
||||
infos.push("Tiny Encrypt File Info".to_string());
|
||||
let compressed = if meta.compress { " [compressed]" } else { "" };
|
||||
@@ -37,7 +42,7 @@ pub fn info(path: PathBuf) -> XResult<()> {
|
||||
});
|
||||
infos.push(format!("{}: {}", header("Encrypted comment"), to_yes_or_no(&meta.encrypted_comment)));
|
||||
|
||||
information!("{}\n", infos.join("\n"));
|
||||
success!("{}\n", infos.join("\n"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,11 @@ enum Commands {
|
||||
/// Show file info
|
||||
#[command(arg_required_else_help = true, short_flag = 'I')]
|
||||
Info {
|
||||
/// File
|
||||
path: PathBuf,
|
||||
/// Show raw meta
|
||||
#[arg(long, default_value_t = false)]
|
||||
raw_meta: bool,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -54,8 +58,8 @@ fn main() -> XResult<()> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Commands::Info { path } => {
|
||||
cmd_info::info(path)
|
||||
Commands::Info { path, raw_meta } => {
|
||||
cmd_info::info(path, raw_meta)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user