mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 03:27:44 +00:00
expr: fail fast if there are no operands
This commit is contained in:
parent
af021e0d4f
commit
2e77d99dd4
2 changed files with 6 additions and 2 deletions
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
use clap::{crate_version, Arg, ArgAction, Command};
|
use clap::{crate_version, Arg, ArgAction, Command};
|
||||||
use uucore::{
|
use uucore::{
|
||||||
error::{UResult, USimpleError},
|
error::{UResult, USimpleError, UUsageError},
|
||||||
format_usage, help_about, help_section, help_usage,
|
format_usage, help_about, help_section, help_usage,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -58,6 +58,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
.map(|v| v.into_iter().map(|s| s.as_ref()).collect::<Vec<_>>())
|
.map(|v| v.into_iter().map(|s| s.as_ref()).collect::<Vec<_>>())
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
if token_strings.is_empty() {
|
||||||
|
return Err(UUsageError::new(2, "missing operand"));
|
||||||
|
}
|
||||||
|
|
||||||
match process_expr(&token_strings[..]) {
|
match process_expr(&token_strings[..]) {
|
||||||
Ok(expr_result) => print_expr_ok(&expr_result),
|
Ok(expr_result) => print_expr_ok(&expr_result),
|
||||||
Err(expr_error) => Err(USimpleError::new(2, &expr_error)),
|
Err(expr_error) => Err(USimpleError::new(2, &expr_error)),
|
||||||
|
|
|
@ -11,7 +11,7 @@ fn test_no_arguments() {
|
||||||
new_ucmd!()
|
new_ucmd!()
|
||||||
.fails()
|
.fails()
|
||||||
.code_is(2)
|
.code_is(2)
|
||||||
.stderr_only("expr: missing operand\n");
|
.usage_error("missing operand");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue