From b7e646e710d1409e050b905f14ce5b8b826702c7 Mon Sep 17 00:00:00 2001 From: Jeffrey Finkelstein Date: Sun, 2 Jan 2022 10:28:53 -0500 Subject: [PATCH] tty: return UResult from uumain() function --- src/uu/tty/src/tty.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/uu/tty/src/tty.rs b/src/uu/tty/src/tty.rs index 94e2e6b24..3a02803c0 100644 --- a/src/uu/tty/src/tty.rs +++ b/src/uu/tty/src/tty.rs @@ -12,6 +12,7 @@ use clap::{crate_version, App, Arg}; use std::ffi::CStr; use std::io::Write; +use uucore::error::{UResult, UUsageError}; use uucore::InvalidEncodingHandling; static ABOUT: &str = "Print the file name of the terminal connected to standard input."; @@ -24,21 +25,17 @@ fn usage() -> String { format!("{0} [OPTION]...", 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 args = args .collect_str(InvalidEncodingHandling::ConvertLossy) .accept_any(); - let matches = uu_app().usage(&usage[..]).get_matches_from_safe(args); - - let matches = match matches { - Ok(m) => m, - Err(e) => { - eprint!("{}", e); - return 2; - } - }; + let matches = uu_app() + .usage(&usage[..]) + .get_matches_from_safe(args) + .map_err(|e| UUsageError::new(2, format!("{}", e)))?; let silent = matches.is_present(options::SILENT); @@ -68,9 +65,9 @@ pub fn uumain(args: impl uucore::Args) -> i32 { } if atty::is(atty::Stream::Stdin) { - libc::EXIT_SUCCESS + Ok(()) } else { - libc::EXIT_FAILURE + Err(libc::EXIT_FAILURE.into()) } }