numfmt: return UResult from uumain() function
// spell-checker:ignore N'th M'th
-#[macro_use]
-extern crate uucore;
-
use crate::format::format_and_print;
use crate::options::*;
use crate::units::{Result, Unit};
use clap::{crate_version, App, AppSettings, Arg, ArgMatches};
use std::io::{BufRead, Write};
use uucore::display::Quotable;
+use uucore::error::{UResult, USimpleError};
use uucore::ranges::Range;
pub mod format;
@@ -154,7 +152,8 @@ fn parse_options(args: &ArgMatches) -> Result<NumfmtOptions> {
})
}
-pub fn uumain(args: impl uucore::Args) -> i32 {
+#[uucore_procs::gen_uumain]
+pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage();
let matches = uu_app().usage(&usage[..]).get_matches_from(args);
@@ -168,10 +167,11 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
match result {
Err(e) => {
std::io::stdout().flush().expect("error flushing stdout");
- show_error!("{}", e);
- 1
+ // TODO Change `handle_args()` and `handle_stdin()` so that
+ // they return `UResult`.
+ return Err(USimpleError::new(1, e));
}
- _ => 0,
+ _ => Ok(()),
}
}
