mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-02 05:57:46 +00:00
Merge pull request #2807 from jfinkels/nice-uresult
nice: return UResult from uumain() function
This commit is contained in:
commit
689ae1dd84
1 changed files with 20 additions and 13 deletions
|
@ -16,6 +16,7 @@ use std::io::Error;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
use clap::{crate_version, App, AppSettings, Arg};
|
use clap::{crate_version, App, AppSettings, Arg};
|
||||||
|
use uucore::error::{set_exit_code, UResult, USimpleError, UUsageError};
|
||||||
|
|
||||||
pub mod options {
|
pub mod options {
|
||||||
pub static ADJUSTMENT: &str = "adjustment";
|
pub static ADJUSTMENT: &str = "adjustment";
|
||||||
|
@ -35,7 +36,8 @@ process).",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
@ -45,31 +47,34 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
libc::getpriority(PRIO_PROCESS, 0)
|
libc::getpriority(PRIO_PROCESS, 0)
|
||||||
};
|
};
|
||||||
if Error::last_os_error().raw_os_error().unwrap() != 0 {
|
if Error::last_os_error().raw_os_error().unwrap() != 0 {
|
||||||
show_error!("getpriority: {}", Error::last_os_error());
|
return Err(USimpleError::new(
|
||||||
return 125;
|
125,
|
||||||
|
format!("getpriority: {}", Error::last_os_error()),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let adjustment = match matches.value_of(options::ADJUSTMENT) {
|
let adjustment = match matches.value_of(options::ADJUSTMENT) {
|
||||||
Some(nstr) => {
|
Some(nstr) => {
|
||||||
if !matches.is_present(options::COMMAND) {
|
if !matches.is_present(options::COMMAND) {
|
||||||
show_error!(
|
return Err(UUsageError::new(
|
||||||
"A command must be given with an adjustment.\nTry '{} --help' for more information.",
|
125,
|
||||||
uucore::execution_phrase()
|
"A command must be given with an adjustment.",
|
||||||
);
|
));
|
||||||
return 125;
|
|
||||||
}
|
}
|
||||||
match nstr.parse() {
|
match nstr.parse() {
|
||||||
Ok(num) => num,
|
Ok(num) => num,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
show_error!("\"{}\" is not a valid number: {}", nstr, e);
|
return Err(USimpleError::new(
|
||||||
return 125;
|
125,
|
||||||
|
format!("\"{}\" is not a valid number: {}", nstr, e),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
if !matches.is_present(options::COMMAND) {
|
if !matches.is_present(options::COMMAND) {
|
||||||
println!("{}", niceness);
|
println!("{}", niceness);
|
||||||
return 0;
|
return Ok(());
|
||||||
}
|
}
|
||||||
10_i32
|
10_i32
|
||||||
}
|
}
|
||||||
|
@ -93,11 +98,13 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
show_error!("execvp: {}", Error::last_os_error());
|
show_error!("execvp: {}", Error::last_os_error());
|
||||||
if Error::last_os_error().raw_os_error().unwrap() as c_int == libc::ENOENT {
|
let exit_code = if Error::last_os_error().raw_os_error().unwrap() as c_int == libc::ENOENT {
|
||||||
127
|
127
|
||||||
} else {
|
} else {
|
||||||
126
|
126
|
||||||
}
|
};
|
||||||
|
set_exit_code(exit_code);
|
||||||
|
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