mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
whoami: Added UResult
This commit is contained in:
parent
7d899372a4
commit
06ff6ac4f1
1 changed files with 17 additions and 11 deletions
|
@ -14,9 +14,12 @@ extern crate clap;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate uucore;
|
extern crate uucore;
|
||||||
|
|
||||||
|
use uucore::error::{UResult, USimpleError};
|
||||||
|
|
||||||
mod platform;
|
mod platform;
|
||||||
|
|
||||||
pub fn uumain(args: impl uucore::Args) -> i32 {
|
#[uucore_procs::gen_uumain]
|
||||||
|
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
let app = uu_app();
|
let app = uu_app();
|
||||||
|
|
||||||
if let Err(err) = app.get_matches_from_safe(args) {
|
if let Err(err) = app.get_matches_from_safe(args) {
|
||||||
|
@ -24,15 +27,12 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
|| err.kind == clap::ErrorKind::VersionDisplayed
|
|| err.kind == clap::ErrorKind::VersionDisplayed
|
||||||
{
|
{
|
||||||
println!("{}", err);
|
println!("{}", err);
|
||||||
0
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
show_error!("{}", err);
|
return Err(USimpleError::new(1, format!("{}", err)));
|
||||||
1
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
exec();
|
exec()
|
||||||
|
|
||||||
0
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,13 +40,19 @@ pub fn uu_app() -> App<'static, 'static> {
|
||||||
app_from_crate!()
|
app_from_crate!()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exec() {
|
pub fn exec() -> UResult<()> {
|
||||||
unsafe {
|
unsafe {
|
||||||
match platform::get_username() {
|
match platform::get_username() {
|
||||||
Ok(username) => println!("{}", username),
|
Ok(username) => {
|
||||||
|
println!("{}", username);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Err(err) => match err.raw_os_error() {
|
Err(err) => match err.raw_os_error() {
|
||||||
Some(0) | None => crash!(1, "failed to get username"),
|
Some(0) | None => Err(USimpleError::new(1, "failed to get username")),
|
||||||
Some(_) => crash!(1, "failed to get username: {}", err),
|
Some(_) => Err(USimpleError::new(
|
||||||
|
1,
|
||||||
|
format!("failed to get username: {}", err),
|
||||||
|
)),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue