1
0
Fork 0
mirror of synced 2024-04-27 17:22:13 +12:00

Support the hash type parameter in the CLI (#267)

https://github.com/qarmin/czkawka/issues/266
This commit is contained in:
Thomas Andreas Jung 2021-02-21 05:59:07 +01:00 committed by GitHub
parent 1e94587de8
commit 0f12897687
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View file

@ -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<HashType, &'static str> {
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<CheckingMethod, &'static str> {
match src.to_ascii_lowercase().as_str() {
"name" => Ok(CheckingMethod::Name),

View file

@ -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);