Support the hash type parameter in the CLI (#267)
https://github.com/qarmin/czkawka/issues/266
This commit is contained in:
parent
1e94587de8
commit
0f12897687
|
@ -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),
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue