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

cksum: return UResult from uumain() function

This commit is contained in:
Jeffrey Finkelstein 2021-12-24 13:24:09 -05:00
parent eb87ddbaf7
commit 6f7ce781cb

View file

@ -6,15 +6,14 @@
// file that was distributed with this source code. // file that was distributed with this source code.
// spell-checker:ignore (ToDO) fname // spell-checker:ignore (ToDO) fname
#[macro_use]
extern crate uucore;
use clap::{crate_version, App, Arg}; use clap::{crate_version, App, Arg};
use std::fs::File; use std::fs::File;
use std::io::{self, stdin, BufReader, Read}; use std::io::{self, stdin, BufReader, Read};
use std::path::Path; use std::path::Path;
use uucore::display::Quotable; use uucore::display::Quotable;
use uucore::error::UResult;
use uucore::error::USimpleError;
use uucore::show;
use uucore::InvalidEncodingHandling; use uucore::InvalidEncodingHandling;
// NOTE: CRC_TABLE_LEN *must* be <= 256 as we cast 0..CRC_TABLE_LEN to u8 // NOTE: CRC_TABLE_LEN *must* be <= 256 as we cast 0..CRC_TABLE_LEN to u8
@ -123,7 +122,8 @@ mod options {
pub static FILE: &str = "file"; pub static FILE: &str = "file";
} }
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::Ignore) .collect_str(InvalidEncodingHandling::Ignore)
.accept_any(); .accept_any();
@ -139,25 +139,22 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
match cksum("-") { match cksum("-") {
Ok((crc, size)) => println!("{} {}", crc, size), Ok((crc, size)) => println!("{} {}", crc, size),
Err(err) => { Err(err) => {
show_error!("-: {}", err); return Err(USimpleError::new(2, format!("{}", err)));
return 2;
} }
} }
return 0; return Ok(());
} }
let mut exit_code = 0;
for fname in &files { for fname in &files {
match cksum(fname.as_ref()) { match cksum(fname.as_ref()) {
Ok((crc, size)) => println!("{} {} {}", crc, size, fname), Ok((crc, size)) => println!("{} {} {}", crc, size, fname),
Err(err) => { Err(err) => show!(USimpleError::new(
show_error!("{}: {}", fname.maybe_quote(), err); 2,
exit_code = 2; format!("{}: {}", fname.maybe_quote(), err)
} )),
} }
} }
Ok(())
exit_code
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {