print once when unknown algo
This commit is contained in:
@@ -49,7 +49,7 @@ fn main() -> XResult<()> {
|
|||||||
let options = Options::new_and_parse_args()?;
|
let options = Options::new_and_parse_args()?;
|
||||||
|
|
||||||
if options.version {
|
if options.version {
|
||||||
print_version();
|
print_version(&options);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ fn main() -> XResult<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_version() {
|
fn print_version(options: &Options) {
|
||||||
print!(r#"digest {} - {}
|
print!(r#"digest {} - {}
|
||||||
Copyright (C) 2019 Hatter Jiang.
|
Copyright (C) 2019 Hatter Jiang.
|
||||||
License MIT <https://opensource.org/licenses/MIT>
|
License MIT <https://opensource.org/licenses/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,
|
KECCAK-224, KECCAK-256, KECCAK-384, KECCAK-512,
|
||||||
SM3, RIPEMD160, WHIRLPOOL, BLAKE2S, BLAKE2B
|
SM3, RIPEMD160, WHIRLPOOL, BLAKE2S, BLAKE2B
|
||||||
"#, VERSION, &GIT_HASH[0..7]);
|
"#, 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<Box<dyn Digest>> {
|
fn get_digest_by_algorithm(algo: &str, options: &Options) -> Option<Box<dyn Digest>> {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ use argparse::{ArgumentParser, StoreTrue, Store, List};
|
|||||||
|
|
||||||
pub struct Options {
|
pub struct Options {
|
||||||
pub version: bool,
|
pub version: bool,
|
||||||
|
pub verbose: bool,
|
||||||
pub algorithm: String,
|
pub algorithm: String,
|
||||||
pub file_name_list: Vec<String>,
|
pub file_name_list: Vec<String>,
|
||||||
pub blake_len: usize,
|
pub blake_len: usize,
|
||||||
@@ -12,6 +13,7 @@ impl Options {
|
|||||||
pub fn new() -> Options {
|
pub fn new() -> Options {
|
||||||
Options {
|
Options {
|
||||||
version: false,
|
version: false,
|
||||||
|
verbose: false,
|
||||||
algorithm: "SHA256".to_string(),
|
algorithm: "SHA256".to_string(),
|
||||||
file_name_list: Vec::new(),
|
file_name_list: Vec::new(),
|
||||||
blake_len: 0_usize,
|
blake_len: 0_usize,
|
||||||
@@ -24,7 +26,8 @@ impl Options {
|
|||||||
ap.set_description("digest - command line digest tool.");
|
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.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.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.refer(&mut self.file_name_list).add_argument("File names", List, "File names to be digested");
|
||||||
ap.parse_args_or_exit();
|
ap.parse_args_or_exit();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user