mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-02 05:57:46 +00:00
Merge pull request #3593 from str4d/2930-hashsum-isolate-non-gnu-options
hashsum: Refactor `uu_app` to isolate non-"GNU Coreutils" options
This commit is contained in:
commit
f36b58854b
2 changed files with 56 additions and 45 deletions
12
build.rs
12
build.rs
|
@ -104,21 +104,25 @@ pub fn main() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let map_value = format!("({krate}::uumain, {krate}::uu_app_common)", krate = krate);
|
let map_value = format!("({krate}::uumain, {krate}::uu_app_common)", krate = krate);
|
||||||
|
let map_value_bits =
|
||||||
|
format!("({krate}::uumain, {krate}::uu_app_bits)", krate = krate);
|
||||||
|
let map_value_b3sum =
|
||||||
|
format!("({krate}::uumain, {krate}::uu_app_b3sum)", krate = krate);
|
||||||
phf_map.entry("md5sum", &map_value);
|
phf_map.entry("md5sum", &map_value);
|
||||||
phf_map.entry("sha1sum", &map_value);
|
phf_map.entry("sha1sum", &map_value);
|
||||||
phf_map.entry("sha224sum", &map_value);
|
phf_map.entry("sha224sum", &map_value);
|
||||||
phf_map.entry("sha256sum", &map_value);
|
phf_map.entry("sha256sum", &map_value);
|
||||||
phf_map.entry("sha384sum", &map_value);
|
phf_map.entry("sha384sum", &map_value);
|
||||||
phf_map.entry("sha512sum", &map_value);
|
phf_map.entry("sha512sum", &map_value);
|
||||||
phf_map.entry("sha3sum", &map_value);
|
phf_map.entry("sha3sum", &map_value_bits);
|
||||||
phf_map.entry("sha3-224sum", &map_value);
|
phf_map.entry("sha3-224sum", &map_value);
|
||||||
phf_map.entry("sha3-256sum", &map_value);
|
phf_map.entry("sha3-256sum", &map_value);
|
||||||
phf_map.entry("sha3-384sum", &map_value);
|
phf_map.entry("sha3-384sum", &map_value);
|
||||||
phf_map.entry("sha3-512sum", &map_value);
|
phf_map.entry("sha3-512sum", &map_value);
|
||||||
phf_map.entry("shake128sum", &map_value);
|
phf_map.entry("shake128sum", &map_value_bits);
|
||||||
phf_map.entry("shake256sum", &map_value);
|
phf_map.entry("shake256sum", &map_value_bits);
|
||||||
phf_map.entry("b2sum", &map_value);
|
phf_map.entry("b2sum", &map_value);
|
||||||
phf_map.entry("b3sum", &map_value);
|
phf_map.entry("b3sum", &map_value_b3sum);
|
||||||
tf.write_all(
|
tf.write_all(
|
||||||
format!(
|
format!(
|
||||||
"#[path=\"{dir}/test_{krate}.rs\"]\nmod test_{krate};\n",
|
"#[path=\"{dir}/test_{krate}.rs\"]\nmod test_{krate};\n",
|
||||||
|
|
|
@ -54,27 +54,6 @@ struct Options {
|
||||||
output_bits: usize,
|
output_bits: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_custom_binary(program: &str) -> bool {
|
|
||||||
matches!(
|
|
||||||
program,
|
|
||||||
"md5sum"
|
|
||||||
| "sha1sum"
|
|
||||||
| "sha224sum"
|
|
||||||
| "sha256sum"
|
|
||||||
| "sha384sum"
|
|
||||||
| "sha512sum"
|
|
||||||
| "sha3sum"
|
|
||||||
| "sha3-224sum"
|
|
||||||
| "sha3-256sum"
|
|
||||||
| "sha3-384sum"
|
|
||||||
| "sha3-512sum"
|
|
||||||
| "shake128sum"
|
|
||||||
| "shake256sum"
|
|
||||||
| "b2sum"
|
|
||||||
| "b3sum"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(clippy::cognitive_complexity)]
|
#[allow(clippy::cognitive_complexity)]
|
||||||
fn detect_algo(
|
fn detect_algo(
|
||||||
program: &str,
|
program: &str,
|
||||||
|
@ -373,11 +352,6 @@ pub fn uu_app_common<'a>() -> Command<'a> {
|
||||||
.long("tag")
|
.long("tag")
|
||||||
.help("create a BSD-style checksum"),
|
.help("create a BSD-style checksum"),
|
||||||
)
|
)
|
||||||
.arg(
|
|
||||||
Arg::new("no-names")
|
|
||||||
.long("no-names")
|
|
||||||
.help("Omits filenames in the output (option not present in GNU/Coreutils)"),
|
|
||||||
)
|
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("text")
|
Arg::new("text")
|
||||||
.short('t')
|
.short('t')
|
||||||
|
@ -408,16 +382,6 @@ pub fn uu_app_common<'a>() -> Command<'a> {
|
||||||
.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)
|
|
||||||
.arg(
|
|
||||||
Arg::new("bits")
|
|
||||||
.long("bits")
|
|
||||||
.help("set the size of the output (only for SHAKE)")
|
|
||||||
.takes_value(true)
|
|
||||||
.value_name("BITS")
|
|
||||||
// XXX: should we actually use validators? they're not particularly efficient
|
|
||||||
.validator(is_valid_bit_num),
|
|
||||||
)
|
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("FILE")
|
Arg::new("FILE")
|
||||||
.index(1)
|
.index(1)
|
||||||
|
@ -428,8 +392,37 @@ pub fn uu_app_common<'a>() -> Command<'a> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn uu_app_b3sum<'a>() -> Command<'a> {
|
||||||
|
uu_app_b3sum_opts(uu_app_common())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn uu_app_b3sum_opts(command: Command) -> Command {
|
||||||
|
command.arg(
|
||||||
|
Arg::new("no-names")
|
||||||
|
.long("no-names")
|
||||||
|
.help("Omits filenames in the output (option not present in GNU/Coreutils)"),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn uu_app_bits<'a>() -> Command<'a> {
|
||||||
|
uu_app_opt_bits(uu_app_common())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn uu_app_opt_bits(command: Command) -> Command {
|
||||||
|
// Needed for variable-length output sums (e.g. SHAKE)
|
||||||
|
command.arg(
|
||||||
|
Arg::new("bits")
|
||||||
|
.long("bits")
|
||||||
|
.help("set the size of the output (only for SHAKE)")
|
||||||
|
.takes_value(true)
|
||||||
|
.value_name("BITS")
|
||||||
|
// XXX: should we actually use validators? they're not particularly efficient
|
||||||
|
.validator(is_valid_bit_num),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn uu_app_custom<'a>() -> Command<'a> {
|
pub fn uu_app_custom<'a>() -> Command<'a> {
|
||||||
let mut command = uu_app_common();
|
let mut command = uu_app_b3sum_opts(uu_app_opt_bits(uu_app_common()));
|
||||||
let algorithms = &[
|
let algorithms = &[
|
||||||
("md5", "work with MD5"),
|
("md5", "work with MD5"),
|
||||||
("sha1", "work with SHA1"),
|
("sha1", "work with SHA1"),
|
||||||
|
@ -463,11 +456,25 @@ pub fn uu_app_custom<'a>() -> Command<'a> {
|
||||||
// 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<'a>(binary_name: &str) -> Command<'a> {
|
fn uu_app<'a>(binary_name: &str) -> Command<'a> {
|
||||||
if !is_custom_binary(binary_name) {
|
match binary_name {
|
||||||
uu_app_custom()
|
// These all support the same options.
|
||||||
} else {
|
"md5sum" | "sha1sum" | "sha224sum" | "sha256sum" | "sha384sum" | "sha512sum" => {
|
||||||
uu_app_common()
|
uu_app_common()
|
||||||
}
|
}
|
||||||
|
// b2sum supports the md5sum options plus -l/--length.
|
||||||
|
"b2sum" => uu_app_common(), // TODO: Implement -l/--length
|
||||||
|
// These have never been part of GNU Coreutils, but can function with the same
|
||||||
|
// options as md5sum.
|
||||||
|
"sha3-224sum" | "sha3-256sum" | "sha3-384sum" | "sha3-512sum" => uu_app_common(),
|
||||||
|
// These have never been part of GNU Coreutils, and require an additional --bits
|
||||||
|
// option to specify their output size.
|
||||||
|
"sha3sum" | "shake128sum" | "shake256sum" => uu_app_bits(),
|
||||||
|
// b3sum has never been part of GNU Coreutils, and has a --no-names option in
|
||||||
|
// addition to the b2sum options.
|
||||||
|
"b3sum" => uu_app_b3sum(),
|
||||||
|
// We're probably just being called as `hashsum`, so give them everything.
|
||||||
|
_ => uu_app_custom(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue