Skip to content

Commit

Permalink
Bump clap to v4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sorairolake committed Oct 3, 2022
1 parent df71368 commit e4dfb96
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 83 deletions.
40 changes: 8 additions & 32 deletions b3sum/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 b3sum/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pure = ["blake3/pure"]
[dependencies]
anyhow = "1.0.25"
blake3 = { version = "1", path = "..", features = ["rayon"] }
clap = { version = "3.2.21", features = ["derive"] }
clap = { version = "4.0.8", features = ["derive"] }
hex = "0.4.0"
memmap2 = "0.5.3"
rayon = "1.2.1"
Expand Down
59 changes: 28 additions & 31 deletions b3sum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,34 @@ A command line utility for calculating
Coreutils tools like `b2sum` or `md5sum`.

```
b3sum 1.3.1
USAGE:
b3sum [OPTIONS] [FILE]...
ARGS:
<FILE>... Files to hash, or checkfiles to check. When no file is given,
or when - is given, read standard input.
OPTIONS:
-c, --check Reads BLAKE3 sums from the [FILE]s and checks them
--derive-key <CONTEXT> Uses the key derivation mode, with the given
context string. Cannot be used with --keyed.
-h, --help Print help information
--keyed Uses the keyed mode. The secret key is read from standard
input, and it must be exactly 32 raw bytes.
-l, --length <LEN> The number of output bytes, prior to hex
encoding [default: 32]
--no-mmap Disables memory mapping. Currently this also disables
multithreading.
--no-names Omits filenames in the output
--num-threads <NUM> The maximum number of threads to use. By
default, this is the number of logical cores.
If this flag is omitted, or if its value is 0,
RAYON_NUM_THREADS is also respected.
--quiet Skips printing OK for each successfully verified file.
Must be used with --check.
--raw Writes raw output bytes to stdout, rather than hex.
--no-names is implied. In this case, only a single
input is allowed.
-V, --version Print version information
Usage: b3sum [OPTIONS] [FILE]...
Arguments:
[FILE]... Files to hash, or checkfiles to check. When no file is given,
or when - is given, read standard input.
Options:
-l, --length <LEN> The number of output bytes, prior to hex
encoding [default: 32]
--num-threads <NUM> The maximum number of threads to use. By
default, this is the number of logical cores.
If this flag is omitted, or if its value is 0,
RAYON_NUM_THREADS is also respected.
--keyed Uses the keyed mode. The secret key is read from standard
input, and it must be exactly 32 raw bytes.
--derive-key <CONTEXT> Uses the key derivation mode, with the given
context string. Cannot be used with --keyed.
--no-mmap Disables memory mapping. Currently this also disables
multithreading.
--no-names Omits filenames in the output
--raw Writes raw output bytes to stdout, rather than hex.
--no-names is implied. In this case, only a single
input is allowed.
-c, --check Reads BLAKE3 sums from the [FILE]s and checks them
--quiet Skips printing OK for each successfully verified file.
Must be used with --check.
-h, --help Print help information
-V, --version Print version information
```

See also [this document about how the `--check` flag
Expand Down
48 changes: 29 additions & 19 deletions b3sum/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,73 +12,73 @@ mod unit_tests;

const NAME: &str = "b3sum";

const DERIVE_KEY_ARG: &str = "derive-key";
const DERIVE_KEY_ARG: &str = "derive_key";
const KEYED_ARG: &str = "keyed";
const LENGTH_ARG: &str = "length";
const NO_NAMES_ARG: &str = "no-names";
const NO_NAMES_ARG: &str = "no_names";
const RAW_ARG: &str = "raw";
const CHECK_ARG: &str = "check";

#[derive(Parser)]
#[clap(version)]
#[command(version)]
struct Inner {
/// Files to hash, or checkfiles to check. When no file is given,
/// or when - is given, read standard input.
#[clap(value_parser, verbatim_doc_comment)]
#[arg(verbatim_doc_comment)]
file: Vec<PathBuf>,

/// The number of output bytes, prior to hex
/// encoding
#[clap(
long,
#[arg(
verbatim_doc_comment,
short,
value_name("LEN"),
long,
default_value_t = blake3::OUT_LEN as u64,
verbatim_doc_comment
value_name("LEN")
)]
length: u64,

/// The maximum number of threads to use. By
/// default, this is the number of logical cores.
/// If this flag is omitted, or if its value is 0,
/// RAYON_NUM_THREADS is also respected.
#[clap(long, value_name("NUM"), verbatim_doc_comment)]
#[arg(verbatim_doc_comment, long, value_name("NUM"))]
num_threads: Option<usize>,

/// Uses the keyed mode. The secret key is read from standard
/// input, and it must be exactly 32 raw bytes.
#[clap(long, requires("file"), verbatim_doc_comment)]
#[arg(verbatim_doc_comment, long, requires("file"))]
keyed: bool,

/// Uses the key derivation mode, with the given
/// context string. Cannot be used with --keyed.
#[clap(
#[arg(
verbatim_doc_comment,
long,
conflicts_with(KEYED_ARG),
value_name("CONTEXT"),
verbatim_doc_comment
conflicts_with(KEYED_ARG)
)]
derive_key: Option<String>,

/// Disables memory mapping. Currently this also disables
/// multithreading.
#[clap(long, verbatim_doc_comment)]
#[arg(verbatim_doc_comment, long)]
no_mmap: bool,

/// Omits filenames in the output
#[clap(long)]
#[arg(long)]
no_names: bool,

/// Writes raw output bytes to stdout, rather than hex.
/// --no-names is implied. In this case, only a single
/// input is allowed.
#[clap(long, verbatim_doc_comment)]
#[arg(verbatim_doc_comment, long)]
raw: bool,

/// Reads BLAKE3 sums from the [FILE]s and checks them
#[clap(
long,
#[arg(
short,
long,
conflicts_with(DERIVE_KEY_ARG),
conflicts_with(KEYED_ARG),
conflicts_with(LENGTH_ARG),
Expand All @@ -89,7 +89,7 @@ struct Inner {

/// Skips printing OK for each successfully verified file.
/// Must be used with --check.
#[clap(long, requires(CHECK_ARG), verbatim_doc_comment)]
#[arg(verbatim_doc_comment, long, requires(CHECK_ARG))]
quiet: bool,
}

Expand Down Expand Up @@ -594,3 +594,13 @@ fn main() -> Result<()> {
std::process::exit(if some_file_failed { 1 } else { 0 });
})
}

#[cfg(test)]
mod test {
use clap::CommandFactory;

#[test]
fn test_args() {
crate::Inner::command().debug_assert();
}
}

0 comments on commit e4dfb96

Please sign in to comment.