Skip to content

Commit bcef1d6

Browse files
nproc: use UResult
1 parent f015b04 commit bcef1d6

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/uu/nproc/src/nproc.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77

88
// spell-checker:ignore (ToDO) NPROCESSORS nprocs numstr threadstr sysconf
99

10-
#[macro_use]
11-
extern crate uucore;
12-
1310
use clap::{crate_version, App, Arg};
1411
use std::env;
12+
use uucore::display::Quotable;
13+
use uucore::error::{UResult, USimpleError};
1514

1615
#[cfg(target_os = "linux")]
1716
pub const _SC_NPROCESSORS_CONF: libc::c_int = 83;
@@ -31,16 +30,19 @@ fn usage() -> String {
3130
format!("{0} [OPTIONS]...", uucore::execution_phrase())
3231
}
3332

34-
pub fn uumain(args: impl uucore::Args) -> i32 {
33+
#[uucore_procs::gen_uumain]
34+
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
3535
let usage = usage();
3636
let matches = uu_app().usage(&usage[..]).get_matches_from(args);
3737

3838
let mut ignore = match matches.value_of(OPT_IGNORE) {
3939
Some(numstr) => match numstr.parse() {
4040
Ok(num) => num,
4141
Err(e) => {
42-
show_error!("\"{}\" is not a valid number: {}", numstr, e);
43-
return 1;
42+
return Err(USimpleError::new(
43+
1,
44+
format!("{} is not a valid number: {}", numstr.quote(), e),
45+
));
4446
}
4547
},
4648
None => 0,
@@ -66,7 +68,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
6668
cores -= ignore;
6769
}
6870
println!("{}", cores);
69-
0
71+
Ok(())
7072
}
7173

7274
pub fn uu_app() -> App<'static, 'static> {

0 commit comments

Comments
 (0)