1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-08-02 05:57:46 +00:00

sync: return UResult from uumain() function

This commit is contained in:
Jeffrey Finkelstein 2021-12-31 13:59:20 -05:00
parent cb051e7416
commit 4e16717c22

View file

@ -9,14 +9,10 @@
extern crate libc; extern crate libc;
#[macro_use]
extern crate uucore;
use clap::{crate_version, App, Arg}; use clap::{crate_version, App, Arg};
use std::path::Path; use std::path::Path;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError};
static EXIT_ERR: i32 = 1;
static ABOUT: &str = "Synchronize cached writes to persistent storage"; static ABOUT: &str = "Synchronize cached writes to persistent storage";
pub mod options { pub mod options {
@ -164,7 +160,8 @@ fn usage() -> String {
format!("{0} [OPTION]... FILE...", uucore::execution_phrase()) format!("{0} [OPTION]... FILE...", uucore::execution_phrase())
} }
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);
@ -176,11 +173,10 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
for f in &files { for f in &files {
if !Path::new(&f).exists() { if !Path::new(&f).exists() {
crash!( return Err(USimpleError::new(
EXIT_ERR, 1,
"cannot stat {}: No such file or directory", format!("cannot stat {}: No such file or directory", f.quote()),
f.quote() ));
);
} }
} }
@ -194,7 +190,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
} else { } else {
sync(); sync();
} }
0 Ok(())
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {