From 21c1d832ae5c306b4a8e1187b0e3805c441ec7df Mon Sep 17 00:00:00 2001 From: Jeffrey Finkelstein Date: Fri, 31 Dec 2021 14:44:57 -0500 Subject: [PATCH] tr: return UResult from uumain() function --- src/uu/tr/src/tr.rs | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/uu/tr/src/tr.rs b/src/uu/tr/src/tr.rs index fbc4bab9b..ffa45ce0e 100644 --- a/src/uu/tr/src/tr.rs +++ b/src/uu/tr/src/tr.rs @@ -10,9 +10,6 @@ // spell-checker:ignore (ToDO) allocs bset dflag cflag sflag tflag -#[macro_use] -extern crate uucore; - mod expand; use bit_set::BitSet; @@ -21,6 +18,7 @@ use fnv::FnvHashMap; use std::io::{stdin, stdout, BufRead, BufWriter, Write}; use crate::expand::ExpandSet; +use uucore::error::{UResult, UUsageError}; use uucore::{display::Quotable, InvalidEncodingHandling}; static ABOUT: &str = "translate or delete characters"; @@ -238,7 +236,8 @@ writing to standard output." .to_string() } -pub fn uumain(args: impl uucore::Args) -> i32 { +#[uucore_procs::gen_uumain] +pub fn uumain(args: impl uucore::Args) -> UResult<()> { let args = args .collect_str(InvalidEncodingHandling::ConvertLossy) .accept_any(); @@ -262,20 +261,14 @@ pub fn uumain(args: impl uucore::Args) -> i32 { .unwrap_or_default(); if sets.is_empty() { - show_error!( - "missing operand\nTry '{} --help' for more information.", - uucore::execution_phrase() - ); - return 1; + return Err(UUsageError::new(1, "missing operand")); } if !(delete_flag || squeeze_flag) && sets.len() < 2 { - show_error!( - "missing operand after {}\nTry '{} --help' for more information.", - sets[0].quote(), - uucore::execution_phrase() - ); - return 1; + return Err(UUsageError::new( + 1, + format!("missing operand after {}", sets[0].quote()), + )); } let stdin = stdin(); @@ -307,8 +300,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 { let op = TranslateOperation::new(set1, &mut set2, truncate_flag, complement_flag); translate_input(&mut locked_stdin, &mut buffered_stdout, op); } - - 0 + Ok(()) } pub fn uu_app() -> App<'static, 'static> {