1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-01 05:27:45 +00:00

Merge pull request #2810 from jfinkels/numfmt-uresult

numfmt: return UResult from uumain() function
This commit is contained in:
Terts Diepraam 2021-12-29 15:08:27 +01:00 committed by GitHub
commit 463127f59f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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