feat: cmd info works
This commit is contained in:
34
src/cmd_info.rs
Normal file
34
src/cmd_info.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use std::fs::File;
|
||||
use std::path::PathBuf;
|
||||
use rust_util::{information, opt_result, simple_error, XResult};
|
||||
use crate::file;
|
||||
|
||||
pub fn info(path: PathBuf) -> 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);
|
||||
// println!("{}", serde_json::to_string_pretty(&meta).expect("SHOULD NOT HAPPEN"));
|
||||
|
||||
let mut infos = vec![];
|
||||
infos.push("Tiny Encrypt File Info".to_string());
|
||||
infos.push(format!("File..............: {}", path_display));
|
||||
infos.push(format!("File size.........: {} bytes", meta.file_length));
|
||||
infos.push(format!("Enc file summary..: Version: {}, Agent: {}", meta.version, meta.user_agent));
|
||||
infos.push(format!("Last modified.....: {}", meta.file_last_modified));
|
||||
infos.push(format!("Enc file created..: {}", meta.created));
|
||||
infos.push(format!("Envelops..........: KMS: {}, PGP: {}",
|
||||
to_yes_or_no(&meta.envelop),
|
||||
to_yes_or_no(&meta.pgp_envelop)
|
||||
));
|
||||
meta.pgp_fingerprint.map(|fingerprint| {
|
||||
infos.push(format!("PGP fingerprint...: {}", fingerprint));
|
||||
});
|
||||
infos.push(format!("Encrypted comment.: {}", to_yes_or_no(&meta.encrypted_comment)));
|
||||
|
||||
information!("{}\n", infos.join("\n"));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn to_yes_or_no(opt: &Option<String>) -> String {
|
||||
opt.as_ref().map(|_| "YES".to_string()).unwrap_or_else(|| "NO".to_string())
|
||||
}
|
||||
Reference in New Issue
Block a user