From f8f63461264208ccd26842ec02f61f120c751072 Mon Sep 17 00:00:00 2001 From: zhitkoff Date: Sat, 25 Nov 2023 18:16:34 -0500 Subject: [PATCH] wc: fix FilesDisabled error message --- src/uu/wc/src/wc.rs | 12 ++++++++---- tests/by-util/test_wc.rs | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/uu/wc/src/wc.rs b/src/uu/wc/src/wc.rs index 663bbda15..ae9b24f5d 100644 --- a/src/uu/wc/src/wc.rs +++ b/src/uu/wc/src/wc.rs @@ -167,7 +167,7 @@ impl<'a> Inputs<'a> { None => Ok(Self::Files0From(input)), } } - (Some(_), Some(_)) => Err(WcError::FilesDisabled.into()), + (Some(mut files), Some(_)) => Err(WcError::files_disabled(files.next()).into()), } } @@ -342,8 +342,8 @@ impl TotalWhen { #[derive(Debug, Error)] enum WcError { - #[error("file operands cannot be combined with --files0-from")] - FilesDisabled, + #[error("extra operand '{extra}'\nfile operands cannot be combined with --files0-from")] + FilesDisabled { extra: Cow<'static, str> }, #[error("when reading file names from stdin, no file name of '-' allowed")] StdinReprNotAllowed, #[error("invalid zero-length file name")] @@ -365,11 +365,15 @@ impl WcError { None => Self::ZeroLengthFileName, } } + fn files_disabled(first_extra: Option<&OsString>) -> Self { + let extra = first_extra.unwrap().to_string_lossy().into_owned().into(); + Self::FilesDisabled { extra } + } } impl UError for WcError { fn usage(&self) -> bool { - matches!(self, Self::FilesDisabled) + matches!(self, Self::FilesDisabled { .. }) } } diff --git a/tests/by-util/test_wc.rs b/tests/by-util/test_wc.rs index 6417470c5..8358a542a 100644 --- a/tests/by-util/test_wc.rs +++ b/tests/by-util/test_wc.rs @@ -423,7 +423,8 @@ fn test_files_from_pseudo_filesystem() { #[test] fn test_files0_disabled_files_argument() { - const MSG: &str = "file operands cannot be combined with --files0-from"; + const MSG: &str = + "extra operand 'lorem_ipsum.txt'\nfile operands cannot be combined with --files0-from"; new_ucmd!() .args(&["--files0-from=files0_list.txt"]) .arg("lorem_ipsum.txt")