diff --git a/src/cmd_info.rs b/src/cmd_info.rs index 1f40eda..13cd256 100644 --- a/src/cmd_info.rs +++ b/src/cmd_info.rs @@ -75,7 +75,7 @@ pub fn info_single(path: &PathBuf, cmd_info: &CmdInfo) -> XResult<()> { envelops.iter().enumerate().for_each(|(i, envelop)| { infos.push(format!("{}: {}", header(&format!("Envelop #{}", i + 1)), - util_envelop::format_envelop_with_type_with(envelop, &config, Some(10)) + util_envelop::format_envelop(envelop, &config) )); }) } diff --git a/src/util_envelop.rs b/src/util_envelop.rs index ae0e19a..b0e78e8 100644 --- a/src/util_envelop.rs +++ b/src/util_envelop.rs @@ -1,11 +1,9 @@ +use rust_util::iff; + use crate::config::{TinyEncryptConfig, TinyEncryptConfigEnvelop}; use crate::spec::TinyEncryptEnvelop; pub fn format_envelop(envelop: &TinyEncryptEnvelop, config: &Option) -> String { - format_envelop_with_type_with(envelop, config, None) -} - -pub fn format_envelop_with_type_with(envelop: &TinyEncryptEnvelop, config: &Option, type_width: Option) -> String { let config_envelop = config.as_ref().and_then(|c| c.find_by_kid(&envelop.kid)); let envelop_kid = config_envelop.and_then(|e| e.sid.as_ref()) .map(|sid| format!(", Sid: {}", sid)) @@ -14,7 +12,7 @@ pub fn format_envelop_with_type_with(envelop: &TinyEncryptEnvelop, config: &Opti let desc = envelop_desc.as_ref() .map(|desc| format!(", Desc: {}", desc)) .unwrap_or_else(|| "".to_string()); - format!("{}{}{}", with_with(&envelop.r#type.get_upper_name(), type_width), envelop_kid, desc) + format!("{}{}{}", with_with(&envelop.r#type.get_upper_name(), 10), envelop_kid, desc) } fn get_envelop_desc(envelop: &TinyEncryptEnvelop, config_envelop: &Option<&TinyEncryptConfigEnvelop>) -> Option { @@ -27,13 +25,6 @@ fn get_envelop_desc(envelop: &TinyEncryptEnvelop, config_envelop: &Option<&TinyE None } -fn with_with(s: &str, width: Option) -> String { - match width { - None => s.to_string(), - Some(w) => if s.len() < w { - format!("{}{}", s, " ".repeat(w - s.len())) - } else { - s.to_string() - } - } +fn with_with(s: &str, width: usize) -> String { + iff!(s.len() < width, format!("{}{}", s, " ".repeat(width - s.len())), s.to_string()) }