From 0f1289768732e993c4d67a431c7f3ce308d8d79b Mon Sep 17 00:00:00 2001 From: Thomas Andreas Jung Date: Sun, 21 Feb 2021 05:59:07 +0100 Subject: [PATCH] Support the hash type parameter in the CLI (#267) https://github.com/qarmin/czkawka/issues/266 --- czkawka_cli/src/commands.rs | 14 +++++++++++++- czkawka_cli/src/main.rs | 2 ++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/czkawka_cli/src/commands.rs b/czkawka_cli/src/commands.rs index 08de2af..abda895 100644 --- a/czkawka_cli/src/commands.rs +++ b/czkawka_cli/src/commands.rs @@ -1,4 +1,4 @@ -use czkawka_core::duplicate::{CheckingMethod, DeleteMethod}; +use czkawka_core::duplicate::{CheckingMethod, DeleteMethod, HashType}; use czkawka_core::same_music::MusicSimilarity; use czkawka_core::similar_images::Similarity; use std::path::PathBuf; @@ -23,6 +23,9 @@ pub enum Commands { search_method: CheckingMethod, #[structopt(short = "D", long, default_value = "NONE", parse(try_from_str = parse_delete_method), help = "Delete method (AEN, AEO, ON, OO, HARD)", long_help = "Methods to delete the files.\nAEN - All files except the newest,\nAEO - All files except the oldest,\nON - Only 1 file, the newest,\nOO - Only 1 file, the oldest\nHARD - create hard link\nNONE - not delete files")] delete_method: DeleteMethod, + #[structopt(short, long, default_value = "BLAKE3", parse(try_from_str = parse_hash_type), + help="Hash type (BLAKE3, CRC32, XXH3)")] + hash_type: HashType, #[structopt(flatten)] file_to_save: FileToSave, #[structopt(flatten)] @@ -234,6 +237,15 @@ impl FileToSave { } } +fn parse_hash_type(src: &str) -> Result { + match src.to_ascii_lowercase().as_str() { + "blake3" => Ok(HashType::Blake3), + "crc32" => Ok(HashType::CRC32), + "xxh3" => Ok(HashType::XXH3), + _ => Err("Couldn't parse the hash type (allowed: BLAKE3, CRC32, XXH3)"), + } +} + fn parse_checking_method(src: &str) -> Result { match src.to_ascii_lowercase().as_str() { "name" => Ok(CheckingMethod::Name), diff --git a/czkawka_cli/src/main.rs b/czkawka_cli/src/main.rs index fe9ef37..e599813 100644 --- a/czkawka_cli/src/main.rs +++ b/czkawka_cli/src/main.rs @@ -36,6 +36,7 @@ fn main() { allowed_extensions, search_method, delete_method, + hash_type, file_to_save, not_recursive, } => { @@ -48,6 +49,7 @@ fn main() { df.set_allowed_extensions(allowed_extensions.allowed_extensions.join(",")); df.set_check_method(search_method); df.set_delete_method(delete_method); + df.set_hash_type(hash_type); df.set_recursive_search(!not_recursive.not_recursive); df.find_duplicates(None, None);