Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions src/uu/hashsum/src/hashsum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,10 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
.unwrap_or_else(|| OsStr::new(NAME))
.to_string_lossy();

let args = iter::once(program.clone()).chain(args);
// Add virtual untagged --\0 to use same logic with cksum
let args = iter::once(program.clone())
.chain(iter::once(OsString::from("--\0")))
.chain(args);

// Default binary in Windows, text mode otherwise
let binary_flag_default = cfg!(windows);
Expand Down Expand Up @@ -205,7 +208,7 @@ pub fn uumain(mut args: impl uucore::Args) -> UResult<()> {
mod options {
//pub const ALGORITHM: &str = "algorithm";
pub const FILE: &str = "file";
//pub const UNTAGGED: &str = "untagged";
pub const UNTAGGED: &str = "\0"; // To keep similar logic with cksum
pub const TAG: &str = "tag";
pub const LENGTH: &str = "length";
//pub const RAW: &str = "raw";
Expand All @@ -220,10 +223,8 @@ mod options {
}

pub fn uu_app_common() -> Command {
// --text --arg-deps-check should be error by Arg::new(options::CHECK)...conflicts_with(options::TEXT)
// https://github.com/clap-rs/clap/issues/4520 ?
// Let --{warn,strict,quiet,status,ignore-missing} reject --text and remove them later.
// Bad error message, but not a lie...
// To keep same logic with cksum and avoid https://github.com/clap-rs/clap/issues/4520,
// --text depends on virtual --untagged
Command::new(uucore::util_name())
.version(uucore::crate_version!())
.help_template(uucore::localized_help_template(uucore::util_name()))
Expand Down Expand Up @@ -257,12 +258,19 @@ pub fn uu_app_common() -> Command {
.conflicts_with(options::TEXT)
.conflicts_with(options::TAG),
)
.arg(
Arg::new(options::UNTAGGED)
.long(options::UNTAGGED)
.overrides_with(options::TAG)
.action(ArgAction::SetTrue)
.hide(true),
)
.arg(
Arg::new(options::TAG)
.long("tag")
.help(translate!("hashsum-help-tag"))
.action(ArgAction::SetTrue)
.conflicts_with("text"),
.overrides_with(options::TEXT),
)
.arg(
Arg::new(options::TEXT)
Expand All @@ -279,6 +287,7 @@ pub fn uu_app_common() -> Command {
}
})
.conflicts_with("binary")
.requires(options::UNTAGGED)
.action(ArgAction::SetTrue),
)
.arg(
Expand All @@ -288,7 +297,6 @@ pub fn uu_app_common() -> Command {
.help(translate!("hashsum-help-quiet"))
.action(ArgAction::SetTrue)
.overrides_with_all([options::STATUS, options::WARN])
.conflicts_with("text")
.requires(options::CHECK),
)
.arg(
Expand All @@ -298,23 +306,20 @@ pub fn uu_app_common() -> Command {
.help(translate!("hashsum-help-status"))
.action(ArgAction::SetTrue)
.overrides_with_all([options::QUIET, options::WARN])
.conflicts_with("text")
.requires(options::CHECK),
)
.arg(
Arg::new(options::STRICT)
.long("strict")
.help(translate!("hashsum-help-strict"))
.action(ArgAction::SetTrue)
.conflicts_with("text")
.requires(options::CHECK),
)
.arg(
Arg::new("ignore-missing")
.long("ignore-missing")
.help(translate!("hashsum-help-ignore-missing"))
.action(ArgAction::SetTrue)
.conflicts_with("text")
.requires(options::CHECK),
)
.arg(
Expand All @@ -324,7 +329,6 @@ pub fn uu_app_common() -> Command {
.help(translate!("hashsum-help-warn"))
.action(ArgAction::SetTrue)
.overrides_with_all([options::QUIET, options::STATUS])
.conflicts_with("text")
.requires(options::CHECK),
)
.arg(
Expand Down
13 changes: 13 additions & 0 deletions tests/by-util/test_hashsum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,19 @@ fn test_conflicting_arg() {
.fails_with_code(1);
}

#[cfg(target_os = "linux")]
#[test]
fn test_text_tag_device() {
let scene = TestScenario::new(util_name!());

scene
.ccmd("md5sum")
.arg("--text")
.arg("--tag")
.arg("/dev/null")
.succeeds();
}

#[test]
fn test_tag() {
let scene = TestScenario::new(util_name!());
Expand Down
Loading