Skip to content

Commit

Permalink
Split short summary from full help text
Browse files Browse the repository at this point in the history
  • Loading branch information
sorairolake committed Oct 3, 2022
1 parent e4dfb96 commit cf9edb0
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 56 deletions.
101 changes: 101 additions & 0 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
Expand Up @@ -16,7 +16,7 @@ pure = ["blake3/pure"]
[dependencies]
anyhow = "1.0.25"
blake3 = { version = "1", path = "..", features = ["rayon"] }
clap = { version = "4.0.8", features = ["derive"] }
clap = { version = "4.0.8", features = ["derive", "wrap_help"] }
hex = "0.4.0"
memmap2 = "0.5.3"
rayon = "1.2.1"
Expand Down
46 changes: 23 additions & 23 deletions b3sum/README.md
Expand Up @@ -8,31 +8,31 @@ Coreutils tools like `b2sum` or `md5sum`.
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.
[FILE]... Files to hash, or checkfiles to check
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
-l, --length <LEN>
The number of output bytes, prior to hex encoding [default: 32]
--num-threads <NUM>
The maximum number of threads to use
--keyed
Uses the keyed mode
--derive-key <CONTEXT>
Uses the key derivation mode, with the given context string
--no-mmap
Disables memory mapping
--no-names
Omits filenames in the output
--raw
Writes raw output bytes to stdout, rather than hex
-c, --check
Reads BLAKE3 sums from the [FILE]s and checks them
--quiet
Skips printing OK for each successfully verified file
-h, --help
Print help information (use `--help` for more detail)
-V, --version
Print version information
```

See also [this document about how the `--check` flag
Expand Down
62 changes: 30 additions & 32 deletions b3sum/src/main.rs
Expand Up @@ -20,62 +20,59 @@ const RAW_ARG: &str = "raw";
const CHECK_ARG: &str = "check";

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

/// The number of output bytes, prior to hex
/// encoding
/// The number of output bytes, prior to hex encoding.
#[arg(
verbatim_doc_comment,
short,
long,
default_value_t = blake3::OUT_LEN as u64,
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.
#[arg(verbatim_doc_comment, long, value_name("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.
#[arg(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.
#[arg(verbatim_doc_comment, long, requires("file"))]
/// Uses the keyed mode.
///
/// The secret key is read from standard input, and it must be exactly 32
/// raw bytes.
#[arg(long, requires("file"))]
keyed: bool,

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

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

/// Omits filenames in the output
/// Omits filenames in the output.
#[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.
#[arg(verbatim_doc_comment, long)]
///
/// --no-names is implied. In this case, only a single input is allowed.
#[arg(long)]
raw: bool,

/// Reads BLAKE3 sums from the [FILE]s and checks them
/// Reads BLAKE3 sums from the [FILE]s and checks them.
#[arg(
short,
long,
Expand All @@ -88,8 +85,9 @@ struct Inner {
check: bool,

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

Expand Down

0 comments on commit cf9edb0

Please sign in to comment.