Skip to content

Commit

Permalink
Fixed --checksum algorithm argument by splitting them into two.
Browse files Browse the repository at this point in the history
  • Loading branch information
PsychedelicShayna committed Sep 14, 2024
1 parent 4262e1e commit a48ac94
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "jw"
version = "2.2.2"
version = "2.2.3"
edition = "2021"

description = "Blazingly fast filesystem traverser and mass file hasher with diff support, powered by jwalk and xxh3!"
Expand Down
42 changes: 27 additions & 15 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ fn checksum_diff(paths: &[String], print_stats: bool) {

fn main() {
let matches = Command::new("jw")
.version("2.0")
.version("2.2.3")
.about("A CLI frontend to jwalk for blazingly fast filesystem traversal!")
.arg(Arg::new("live-print")
.long("live")
Expand All @@ -356,17 +356,27 @@ fn main() {
This will result in a significant drop in performance due to the constant terminal output."))

.arg(Arg::new("checksum")
.long("checksum")
.long("csum")
.short('c')
.num_args(0..=1)
.action(ArgAction::SetTrue)
.help("Output an index containing the hash of every file using the specified algorithm.")
.long_help("Output an index containing the hash of every file using the specified algorithm.
Uses the default algorithm. To specify one use --calgo. Note: specifying --calgo makes this redundant."))

.arg(Arg::new("checksum-algo")
.long("calgo")
.short('C')
.value_parser(["xxh3", "sha224", "sha256", "sha384", "sha512", "md5"])
.default_value("xxh3")
.ignore_case(true)
.value_name("algorithm")
.help("Output an index containing the hash of every file using the specified algorithm.")
.long_help(
"Output an index containing the hash of every file using the specified algorithm.
It is highly recommended you stick with xxh3, as it is significantly more performant,
and directly suited for this use case. SHA2/MD5 are only provided for compatibility."))
.default_value("xxh3")
.help("Performs --csum but with the specified hashing algorithm.")
.long_help("Performs --csum but with the specified hashing algorithm.
Using xxh3 is the recommended choice. Unless you have a reason to use something else,
stick with the default. SHA2 and MD5 are provided for compatibility with other tools
and existing data. If you're only using jw, you stand to gain a large increase in
performance by using xxh3."))

.arg(Arg::new("checksum-threads")
.long("threads")
Expand All @@ -378,7 +388,7 @@ and directly suited for this use case. SHA2/MD5 are only provided for compatibil

.arg(Arg::new("hdiff")
.long("diff")
.short('C')
.short('D')
.value_names(["file1", "file2"])
.num_args(2..)
.help("Validate hashes from two or more files containing output from `jw --checksum`")
Expand Down Expand Up @@ -455,12 +465,14 @@ files you're traversing, the more it begins to add up.")
let options = Options {
live_print: *matches.get_one::<bool>("live-print").unwrap_or(&false),
exclude: exclude_flags,
checksum: matches.contains_id("checksum").then(|| {
matches
.get_one::<String>("checksum")
.map(HashAlgorithm::from)
.unwrap_or(HashAlgorithm::Xxh3)
}),
checksum: (matches.contains_id("checksum") || matches.contains_id("checksum-algo")).then(
|| {
matches
.get_one::<String>("checksum-algo")
.map(HashAlgorithm::from)
.unwrap_or(HashAlgorithm::Xxh3)
},
),
checksum_threads: *matches.get_one("checksum-threads").unwrap_or(&1),
depth: *matches.get_one("depth").unwrap_or(&0),
directories: walk_dirs,
Expand Down

0 comments on commit a48ac94

Please sign in to comment.