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

nproc: use UResult

This commit is contained in:
Thomas Queiroz 2021-11-16 18:02:42 -03:00
parent f015b041ec
commit bcef1d6cca
No known key found for this signature in database
GPG key ID: 229D2DDF7ECA5F8F

View file

@ -7,11 +7,10 @@
// spell-checker:ignore (ToDO) NPROCESSORS nprocs numstr threadstr sysconf // spell-checker:ignore (ToDO) NPROCESSORS nprocs numstr threadstr sysconf
#[macro_use]
extern crate uucore;
use clap::{crate_version, App, Arg}; use clap::{crate_version, App, Arg};
use std::env; use std::env;
use uucore::display::Quotable;
use uucore::error::{UResult, USimpleError};
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
pub const _SC_NPROCESSORS_CONF: libc::c_int = 83; pub const _SC_NPROCESSORS_CONF: libc::c_int = 83;
@ -31,7 +30,8 @@ fn usage() -> String {
format!("{0} [OPTIONS]...", uucore::execution_phrase()) format!("{0} [OPTIONS]...", uucore::execution_phrase())
} }
pub fn uumain(args: impl uucore::Args) -> i32 { #[uucore_procs::gen_uumain]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let usage = usage(); let usage = usage();
let matches = uu_app().usage(&usage[..]).get_matches_from(args); let matches = uu_app().usage(&usage[..]).get_matches_from(args);
@ -39,8 +39,10 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
Some(numstr) => match numstr.parse() { Some(numstr) => match numstr.parse() {
Ok(num) => num, Ok(num) => num,
Err(e) => { Err(e) => {
show_error!("\"{}\" is not a valid number: {}", numstr, e); return Err(USimpleError::new(
return 1; 1,
format!("{} is not a valid number: {}", numstr.quote(), e),
));
} }
}, },
None => 0, None => 0,
@ -66,7 +68,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
cores -= ignore; cores -= ignore;
} }
println!("{}", cores); println!("{}", cores);
0 Ok(())
} }
pub fn uu_app() -> App<'static, 'static> { pub fn uu_app() -> App<'static, 'static> {