1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

Merge pull request #2720 from Smicry/master

head: use UResult in util
This commit is contained in:
Sylvestre Ledru 2021-10-23 17:53:35 +02:00 committed by GitHub
commit 803c05cb4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -10,10 +10,9 @@ use std::convert::TryFrom;
use std::ffi::OsString;
use std::io::{self, ErrorKind, Read, Seek, SeekFrom, Write};
use uucore::display::Quotable;
use uucore::{crash, show_error_custom_description};
use uucore::error::{UResult, USimpleError};
use uucore::show_error_custom_description;
const EXIT_FAILURE: i32 = 1;
const EXIT_SUCCESS: i32 = 0;
const BUF_SIZE: usize = 65536;
const ABOUT: &str = "\
@ -372,7 +371,7 @@ fn head_file(input: &mut std::fs::File, options: &HeadOptions) -> std::io::Resul
}
}
fn uu_head(options: &HeadOptions) -> Result<(), u32> {
fn uu_head(options: &HeadOptions) -> UResult<()> {
let mut error_count = 0;
let mut first = true;
for file in &options.files {
@ -445,23 +444,21 @@ fn uu_head(options: &HeadOptions) -> Result<(), u32> {
first = false;
}
if error_count > 0 {
Err(error_count)
Err(USimpleError::new(1, ""))
} else {
Ok(())
}
}
pub fn uumain(args: impl uucore::Args) -> i32 {
#[uucore_procs::gen_uumain]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let args = match HeadOptions::get_from(args) {
Ok(o) => o,
Err(s) => {
crash!(EXIT_FAILURE, "{}", s);
return Err(USimpleError::new(1, s));
}
};
match uu_head(&args) {
Ok(_) => EXIT_SUCCESS,
Err(_) => EXIT_FAILURE,
}
uu_head(&args)
}
#[cfg(test)]