mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-01 13:37:48 +00:00
hashsum: clap 3
This commit is contained in:
parent
742fe8500c
commit
6e34d8a53c
2 changed files with 28 additions and 29 deletions
|
@ -16,7 +16,7 @@ path = "src/hashsum.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
digest = "0.6.1"
|
digest = "0.6.1"
|
||||||
clap = { version = "2.33", features = ["wrap_help"] }
|
clap = { version = "3.0", features = ["wrap_help", "cargo"] }
|
||||||
hex = "0.2.0"
|
hex = "0.2.0"
|
||||||
libc = "0.2.42"
|
libc = "0.2.42"
|
||||||
memchr = "2"
|
memchr = "2"
|
||||||
|
|
|
@ -74,9 +74,9 @@ fn is_custom_binary(program: &str) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::cognitive_complexity)]
|
#[allow(clippy::cognitive_complexity)]
|
||||||
fn detect_algo<'a>(
|
fn detect_algo(
|
||||||
program: &str,
|
program: &str,
|
||||||
matches: &ArgMatches<'a>,
|
matches: &ArgMatches,
|
||||||
) -> (&'static str, Box<dyn Digest + 'static>, usize) {
|
) -> (&'static str, Box<dyn Digest + 'static>, usize) {
|
||||||
let mut alg: Option<Box<dyn Digest>> = None;
|
let mut alg: Option<Box<dyn Digest>> = None;
|
||||||
let mut name: &'static str = "";
|
let mut name: &'static str = "";
|
||||||
|
@ -270,10 +270,8 @@ fn parse_bit_num(arg: &str) -> Result<usize, ParseIntError> {
|
||||||
arg.parse()
|
arg.parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_valid_bit_num(arg: String) -> Result<(), String> {
|
fn is_valid_bit_num(arg: &str) -> Result<(), String> {
|
||||||
parse_bit_num(&arg)
|
parse_bit_num(arg).map(|_| ()).map_err(|e| format!("{}", e))
|
||||||
.map(|_| ())
|
|
||||||
.map_err(|e| format!("{}", e))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[uucore_procs::gen_uumain]
|
#[uucore_procs::gen_uumain]
|
||||||
|
@ -333,7 +331,7 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uu_app_common() -> App<'static, 'static> {
|
pub fn uu_app_common<'a>() -> App<'a> {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
const BINARY_HELP: &str = "read in binary mode (default)";
|
const BINARY_HELP: &str = "read in binary mode (default)";
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(windows))]
|
||||||
|
@ -346,55 +344,55 @@ pub fn uu_app_common() -> App<'static, 'static> {
|
||||||
.version(crate_version!())
|
.version(crate_version!())
|
||||||
.about("Compute and check message digests.")
|
.about("Compute and check message digests.")
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("binary")
|
Arg::new("binary")
|
||||||
.short("b")
|
.short('b')
|
||||||
.long("binary")
|
.long("binary")
|
||||||
.help(BINARY_HELP),
|
.help(BINARY_HELP),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("check")
|
Arg::new("check")
|
||||||
.short("c")
|
.short('c')
|
||||||
.long("check")
|
.long("check")
|
||||||
.help("read hashsums from the FILEs and check them"),
|
.help("read hashsums from the FILEs and check them"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("tag")
|
Arg::new("tag")
|
||||||
.long("tag")
|
.long("tag")
|
||||||
.help("create a BSD-style checksum"),
|
.help("create a BSD-style checksum"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("text")
|
Arg::new("text")
|
||||||
.short("t")
|
.short('t')
|
||||||
.long("text")
|
.long("text")
|
||||||
.help(TEXT_HELP)
|
.help(TEXT_HELP)
|
||||||
.conflicts_with("binary"),
|
.conflicts_with("binary"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("quiet")
|
Arg::new("quiet")
|
||||||
.short("q")
|
.short('q')
|
||||||
.long("quiet")
|
.long("quiet")
|
||||||
.help("don't print OK for each successfully verified file"),
|
.help("don't print OK for each successfully verified file"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("status")
|
Arg::new("status")
|
||||||
.short("s")
|
.short('s')
|
||||||
.long("status")
|
.long("status")
|
||||||
.help("don't output anything, status code shows success"),
|
.help("don't output anything, status code shows success"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("strict")
|
Arg::new("strict")
|
||||||
.long("strict")
|
.long("strict")
|
||||||
.help("exit non-zero for improperly formatted checksum lines"),
|
.help("exit non-zero for improperly formatted checksum lines"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("warn")
|
Arg::new("warn")
|
||||||
.short("w")
|
.short('w')
|
||||||
.long("warn")
|
.long("warn")
|
||||||
.help("warn about improperly formatted checksum lines"),
|
.help("warn about improperly formatted checksum lines"),
|
||||||
)
|
)
|
||||||
// Needed for variable-length output sums (e.g. SHAKE)
|
// Needed for variable-length output sums (e.g. SHAKE)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("bits")
|
Arg::new("bits")
|
||||||
.long("bits")
|
.long("bits")
|
||||||
.help("set the size of the output (only for SHAKE)")
|
.help("set the size of the output (only for SHAKE)")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
|
@ -403,14 +401,15 @@ pub fn uu_app_common() -> App<'static, 'static> {
|
||||||
.validator(is_valid_bit_num),
|
.validator(is_valid_bit_num),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("FILE")
|
Arg::new("FILE")
|
||||||
.index(1)
|
.index(1)
|
||||||
.multiple(true)
|
.multiple_occurrences(true)
|
||||||
.value_name("FILE"),
|
.value_name("FILE")
|
||||||
|
.allow_invalid_utf8(true),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uu_app_custom() -> App<'static, 'static> {
|
pub fn uu_app_custom<'a>() -> App<'a> {
|
||||||
let mut app = uu_app_common();
|
let mut app = uu_app_common();
|
||||||
let algorithms = &[
|
let algorithms = &[
|
||||||
("md5", "work with MD5"),
|
("md5", "work with MD5"),
|
||||||
|
@ -436,14 +435,14 @@ pub fn uu_app_custom() -> App<'static, 'static> {
|
||||||
];
|
];
|
||||||
|
|
||||||
for (name, desc) in algorithms {
|
for (name, desc) in algorithms {
|
||||||
app = app.arg(Arg::with_name(name).long(name).help(desc));
|
app = app.arg(Arg::new(*name).long(name).help(*desc));
|
||||||
}
|
}
|
||||||
app
|
app
|
||||||
}
|
}
|
||||||
|
|
||||||
// hashsum is handled differently in build.rs, therefore this is not the same
|
// hashsum is handled differently in build.rs, therefore this is not the same
|
||||||
// as in other utilities.
|
// as in other utilities.
|
||||||
fn uu_app(binary_name: &str) -> App<'static, 'static> {
|
fn uu_app<'a>(binary_name: &str) -> App<'a> {
|
||||||
if !is_custom_binary(binary_name) {
|
if !is_custom_binary(binary_name) {
|
||||||
uu_app_custom()
|
uu_app_custom()
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue