mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 12:37:49 +00:00
nproc: use UResult
This commit is contained in:
parent
f015b041ec
commit
bcef1d6cca
1 changed files with 9 additions and 7 deletions
|
@ -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> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue