1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

fixup! csplit: return UResult from uumain() function

This commit is contained in:
Jeffrey Finkelstein 2021-12-26 15:20:09 -05:00
parent a26fbe7c8e
commit a84f57dd1f

View file

@ -13,7 +13,7 @@ use std::{
use clap::{crate_version, App, Arg, ArgMatches};
use regex::Regex;
use uucore::display::Quotable;
use uucore::error::{FromIo, UError, UResult};
use uucore::error::{FromIo, UResult};
use uucore::InvalidEncodingHandling;
mod csplit_error;
@ -715,13 +715,6 @@ mod tests {
}
}
fn to_box<E>(e: E) -> Box<dyn UError>
where
E: UError + 'static,
{
Box::new(e)
}
#[uucore_procs::gen_uumain]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage();
@ -744,7 +737,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let options = CsplitOptions::new(&matches);
if file_name == "-" {
let stdin = io::stdin();
csplit(&options, patterns, stdin.lock()).map_err(to_box)
Ok(csplit(&options, patterns, stdin.lock())?)
} else {
let file = File::open(file_name)
.map_err_context(|| format!("cannot access {}", file_name.quote()))?;
@ -754,7 +747,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
if !file_metadata.is_file() {
return Err(CsplitError::NotRegularFile(file_name.to_string()).into());
}
csplit(&options, patterns, BufReader::new(file)).map_err(to_box)
Ok(csplit(&options, patterns, BufReader::new(file))?)
}
}