mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
more: add error message if the argument is a directory (#1983)
This commit is contained in:
parent
9fbed0b07a
commit
31f5666727
2 changed files with 21 additions and 2 deletions
|
@ -41,7 +41,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
|
|
||||||
let matches = App::new(executable!())
|
let matches = App::new(executable!())
|
||||||
.version(VERSION)
|
.version(VERSION)
|
||||||
.usage(&usage[..])
|
.usage(usage.as_str())
|
||||||
.about(ABOUT)
|
.about(ABOUT)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::FILE)
|
Arg::with_name(options::FILE)
|
||||||
|
@ -52,10 +52,18 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
|
|
||||||
// FixME: fail without panic for now; but `more` should work with no arguments (ie, for piped input)
|
// FixME: fail without panic for now; but `more` should work with no arguments (ie, for piped input)
|
||||||
if let None | Some("-") = matches.value_of(options::FILE) {
|
if let None | Some("-") = matches.value_of(options::FILE) {
|
||||||
println!("{}: incorrect usage", executable!());
|
show_usage_error!("Reading from stdin isn't supported yet.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(x) = matches.value_of(options::FILE) {
|
||||||
|
let path = std::path::Path::new(x);
|
||||||
|
if path.is_dir() {
|
||||||
|
show_usage_error!("'{}' is a directory.", x);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
more(matches);
|
more(matches);
|
||||||
|
|
||||||
0
|
0
|
||||||
|
|
|
@ -6,3 +6,14 @@ fn test_more_no_arg() {
|
||||||
let result = ucmd.run();
|
let result = ucmd.run();
|
||||||
assert!(!result.success);
|
assert!(!result.success);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_more_dir_arg() {
|
||||||
|
let (_, mut ucmd) = at_and_ucmd!();
|
||||||
|
ucmd.arg(".");
|
||||||
|
let result = ucmd.run();
|
||||||
|
assert!(!result.success);
|
||||||
|
const EXPECTED_ERROR_MESSAGE: &str =
|
||||||
|
"more: '.' is a directory.\nTry 'more --help' for more information.";
|
||||||
|
assert_eq!(result.stderr.trim(), EXPECTED_ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue