mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 19:47:45 +00:00
* `hashsum`: add `--zero` option (#4612)
This commit is contained in:
parent
2447849bdc
commit
e7ef9dcd46
2 changed files with 20 additions and 0 deletions
|
@ -47,6 +47,7 @@ struct Options {
|
||||||
strict: bool,
|
strict: bool,
|
||||||
warn: bool,
|
warn: bool,
|
||||||
output_bits: usize,
|
output_bits: usize,
|
||||||
|
zero: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::cognitive_complexity)]
|
#[allow(clippy::cognitive_complexity)]
|
||||||
|
@ -269,6 +270,7 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
|
||||||
let quiet = matches.get_flag("quiet") || status;
|
let quiet = matches.get_flag("quiet") || status;
|
||||||
let strict = matches.get_flag("strict");
|
let strict = matches.get_flag("strict");
|
||||||
let warn = matches.get_flag("warn") && !status;
|
let warn = matches.get_flag("warn") && !status;
|
||||||
|
let zero = matches.get_flag("zero");
|
||||||
|
|
||||||
let opts = Options {
|
let opts = Options {
|
||||||
algoname: name,
|
algoname: name,
|
||||||
|
@ -282,6 +284,7 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
|
||||||
quiet,
|
quiet,
|
||||||
strict,
|
strict,
|
||||||
warn,
|
warn,
|
||||||
|
zero,
|
||||||
};
|
};
|
||||||
|
|
||||||
match matches.get_many::<OsString>("FILE") {
|
match matches.get_many::<OsString>("FILE") {
|
||||||
|
@ -359,6 +362,13 @@ pub fn uu_app_common() -> Command {
|
||||||
.help("warn about improperly formatted checksum lines")
|
.help("warn about improperly formatted checksum lines")
|
||||||
.action(ArgAction::SetTrue),
|
.action(ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::new("zero")
|
||||||
|
.short('z')
|
||||||
|
.long("zero")
|
||||||
|
.help("end each output line with NUL, not newline")
|
||||||
|
.action(ArgAction::SetTrue),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("FILE")
|
Arg::new("FILE")
|
||||||
.index(1)
|
.index(1)
|
||||||
|
@ -613,6 +623,8 @@ where
|
||||||
println!("{} ({}) = {}", options.algoname, filename.display(), sum);
|
println!("{} ({}) = {}", options.algoname, filename.display(), sum);
|
||||||
} else if options.nonames {
|
} else if options.nonames {
|
||||||
println!("{sum}");
|
println!("{sum}");
|
||||||
|
} else if options.zero {
|
||||||
|
print!("{} {}{}\0", sum, binary_marker, filename.display());
|
||||||
} else {
|
} else {
|
||||||
println!("{} {}{}", sum, binary_marker, filename.display());
|
println!("{} {}{}", sum, binary_marker, filename.display());
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,14 @@ macro_rules! test_digest {
|
||||||
.stdout_is("input.txt: OK\n");
|
.stdout_is("input.txt: OK\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_zero() {
|
||||||
|
let ts = TestScenario::new("hashsum");
|
||||||
|
assert_eq!(ts.fixtures.read(EXPECTED_FILE),
|
||||||
|
get_hash!(ts.ucmd().arg(DIGEST_ARG).arg(BITS_ARG).arg("--zero").arg("input.txt").succeeds().no_stderr().stdout_str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
#[test]
|
#[test]
|
||||||
fn test_text_mode() {
|
fn test_text_mode() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue