tr: return UResult from uumain() function

This commit is contained in:
Jeffrey Finkelstein 2021-12-31 14:44:57 -05:00
parent cb051e7416
commit 21c1d832ae

View file

@ -10,9 +10,6 @@
// spell-checker:ignore (ToDO) allocs bset dflag cflag sflag tflag // spell-checker:ignore (ToDO) allocs bset dflag cflag sflag tflag
#[macro_use]
extern crate uucore;
mod expand; mod expand;
use bit_set::BitSet; use bit_set::BitSet;
@ -21,6 +18,7 @@ use fnv::FnvHashMap;
use std::io::{stdin, stdout, BufRead, BufWriter, Write}; use std::io::{stdin, stdout, BufRead, BufWriter, Write};
use crate::expand::ExpandSet; use crate::expand::ExpandSet;
use uucore::error::{UResult, UUsageError};
use uucore::{display::Quotable, InvalidEncodingHandling}; use uucore::{display::Quotable, InvalidEncodingHandling};
static ABOUT: &str = "translate or delete characters"; static ABOUT: &str = "translate or delete characters";
@ -238,7 +236,8 @@ writing to standard output."
.to_string() .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 let args = args
.collect_str(InvalidEncodingHandling::ConvertLossy) .collect_str(InvalidEncodingHandling::ConvertLossy)
.accept_any(); .accept_any();
@ -262,20 +261,14 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
.unwrap_or_default(); .unwrap_or_default();
if sets.is_empty() { if sets.is_empty() {
show_error!( return Err(UUsageError::new(1, "missing operand"));
"missing operand\nTry '{} --help' for more information.",
uucore::execution_phrase()
);
return 1;
} }
if !(delete_flag || squeeze_flag) && sets.len() < 2 { if !(delete_flag || squeeze_flag) && sets.len() < 2 {
show_error!( return Err(UUsageError::new(
"missing operand after {}\nTry '{} --help' for more information.", 1,
sets[0].quote(), format!("missing operand after {}", sets[0].quote()),
uucore::execution_phrase() ));
);
return 1;
} }
let stdin = stdin(); 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); let op = TranslateOperation::new(set1, &mut set2, truncate_flag, complement_flag);
translate_input(&mut locked_stdin, &mut buffered_stdout, op); translate_input(&mut locked_stdin, &mut buffered_stdout, op);
} }
Ok(())
0
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {