From 7b219aee635a38739869a2076c9f034949b36738 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Sat, 2 Mar 2024 03:14:13 +0100 Subject: [PATCH] cksum: implement trivial --tag flag --- src/uu/cksum/src/cksum.rs | 8 ++++++++ tests/by-util/test_cksum.rs | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/uu/cksum/src/cksum.rs b/src/uu/cksum/src/cksum.rs index 6cf04b797..5e9e6f30b 100644 --- a/src/uu/cksum/src/cksum.rs +++ b/src/uu/cksum/src/cksum.rs @@ -286,6 +286,7 @@ mod options { pub const ALGORITHM: &str = "algorithm"; pub const FILE: &str = "file"; pub const UNTAGGED: &str = "untagged"; + pub const TAG: &str = "tag"; pub const LENGTH: &str = "length"; pub const RAW: &str = "raw"; } @@ -396,6 +397,13 @@ pub fn uu_app() -> Command { Arg::new(options::UNTAGGED) .long(options::UNTAGGED) .help("create a reversed style checksum, without digest type") + .action(ArgAction::SetTrue) + .overrides_with(options::TAG), + ) + .arg( + Arg::new(options::TAG) + .long(options::TAG) + .help("create a BSD style checksum, undo --untagged (default)") .action(ArgAction::SetTrue), ) .arg( diff --git a/tests/by-util/test_cksum.rs b/tests/by-util/test_cksum.rs index f07261b74..5e66b572a 100644 --- a/tests/by-util/test_cksum.rs +++ b/tests/by-util/test_cksum.rs @@ -140,6 +140,17 @@ fn test_repeated_flags() { .stdout_is_fixture("md5_single_file.expected"); } +#[test] +fn test_tag_after_untagged() { + new_ucmd!() + .arg("--untagged") + .arg("--tag") + .arg("-a=md5") + .arg("lorem_ipsum.txt") + .succeeds() + .stdout_is_fixture("md5_single_file.expected"); +} + #[test] fn test_algorithm_single_file() { for algo in ALGOS { @@ -220,6 +231,17 @@ fn test_untagged_algorithm_single_file() { } } +#[test] +fn test_untagged_algorithm_after_tag() { + new_ucmd!() + .arg("--tag") + .arg("--untagged") + .arg("--algorithm=md5") + .arg("lorem_ipsum.txt") + .succeeds() + .stdout_is_fixture("untagged/md5_single_file.expected"); +} + #[test] fn test_untagged_algorithm_multiple_files() { for algo in ALGOS {