diff --git a/src/uu/stat/src/stat.rs b/src/uu/stat/src/stat.rs index a0ece4cce..1c5bd8919 100644 --- a/src/uu/stat/src/stat.rs +++ b/src/uu/stat/src/stat.rs @@ -546,10 +546,16 @@ impl Stater { } fn new(matches: &ArgMatches) -> UResult { - let files = matches + let files: Vec = matches .get_many::(options::FILES) .map(|v| v.map(OsString::from).collect()) .unwrap_or_default(); + if files.is_empty() { + return Err(Box::new(USimpleError { + code: 1, + message: "missing operand\nTry 'stat --help' for more information.".to_string(), + })); + } let format_str = if matches.contains_id(options::PRINTF) { matches .get_one::(options::PRINTF) diff --git a/tests/by-util/test_stat.rs b/tests/by-util/test_stat.rs index e918d54e9..189b1d441 100644 --- a/tests/by-util/test_stat.rs +++ b/tests/by-util/test_stat.rs @@ -338,3 +338,10 @@ fn test_stdin_redirect() { .stdout_contains("File: -") .succeeded(); } + +#[test] +fn test_without_argument() { + new_ucmd!() + .fails() + .stderr_contains("missing operand\nTry 'stat --help' for more information."); +}