From dfefab0948635c527765bf3c12446b6de36e7b3d Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 24 Nov 2019 13:10:32 +0800 Subject: [PATCH] print once when unknown algo --- src/main.rs | 7 +++++-- src/opt.rs | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index ddae25b..00c6587 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,7 +49,7 @@ fn main() -> XResult<()> { let options = Options::new_and_parse_args()?; if options.version { - print_version(); + print_version(&options); return Ok(()); } @@ -87,7 +87,7 @@ fn main() -> XResult<()> { Ok(()) } -fn print_version() { +fn print_version(options: &Options) { print!(r#"digest {} - {} Copyright (C) 2019 Hatter Jiang. License MIT @@ -100,6 +100,9 @@ SHA3-224, SHA3-256, SHA3-384, SHA3-512, SHAKE-128, SHAKE-256, KECCAK-224, KECCAK-256, KECCAK-384, KECCAK-512, SM3, RIPEMD160, WHIRLPOOL, BLAKE2S, BLAKE2B "#, VERSION, &GIT_HASH[0..7]); + if options.verbose { + print_message(MessageType::DEBUG, &format!("Full git hash: {}", &GIT_HASH)); + } } fn get_digest_by_algorithm(algo: &str, options: &Options) -> Option> { diff --git a/src/opt.rs b/src/opt.rs index 378bcdd..6eca5bd 100644 --- a/src/opt.rs +++ b/src/opt.rs @@ -3,6 +3,7 @@ use argparse::{ArgumentParser, StoreTrue, Store, List}; pub struct Options { pub version: bool, + pub verbose: bool, pub algorithm: String, pub file_name_list: Vec, pub blake_len: usize, @@ -12,6 +13,7 @@ impl Options { pub fn new() -> Options { Options { version: false, + verbose: false, algorithm: "SHA256".to_string(), file_name_list: Vec::new(), blake_len: 0_usize, @@ -24,7 +26,8 @@ impl Options { ap.set_description("digest - command line digest tool."); ap.refer(&mut self.algorithm).add_option(&["-a", "--algorithm"], Store, "Algorithm, e.g. SHA256, SM3"); ap.refer(&mut self.blake_len).add_option(&["-l", "--blake-len"], Store, "Blake2s/b length, 1~32/64"); - ap.refer(&mut self.version).add_option(&["-v", "--version"], StoreTrue, "Print version"); + ap.refer(&mut self.version).add_option(&["-V", "--version"], StoreTrue, "Print version"); + ap.refer(&mut self.verbose).add_option(&["-v", "--verbose"], StoreTrue, "Verbose"); ap.refer(&mut self.file_name_list).add_argument("File names", List, "File names to be digested"); ap.parse_args_or_exit(); }