mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +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,
|
||||
warn: bool,
|
||||
output_bits: usize,
|
||||
zero: bool,
|
||||
}
|
||||
|
||||
#[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 strict = matches.get_flag("strict");
|
||||
let warn = matches.get_flag("warn") && !status;
|
||||
let zero = matches.get_flag("zero");
|
||||
|
||||
let opts = Options {
|
||||
algoname: name,
|
||||
|
@ -282,6 +284,7 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
|
|||
quiet,
|
||||
strict,
|
||||
warn,
|
||||
zero,
|
||||
};
|
||||
|
||||
match matches.get_many::<OsString>("FILE") {
|
||||
|
@ -359,6 +362,13 @@ pub fn uu_app_common() -> Command {
|
|||
.help("warn about improperly formatted checksum lines")
|
||||
.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::new("FILE")
|
||||
.index(1)
|
||||
|
@ -613,6 +623,8 @@ where
|
|||
println!("{} ({}) = {}", options.algoname, filename.display(), sum);
|
||||
} else if options.nonames {
|
||||
println!("{sum}");
|
||||
} else if options.zero {
|
||||
print!("{} {}{}\0", sum, binary_marker, filename.display());
|
||||
} else {
|
||||
println!("{} {}{}", sum, binary_marker, filename.display());
|
||||
}
|
||||
|
|
|
@ -53,6 +53,14 @@ macro_rules! test_digest {
|
|||
.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)]
|
||||
#[test]
|
||||
fn test_text_mode() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue