1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 19:17:43 +00:00

Merge pull request #5310 from tertsdiepraam/expose-whoami

Expose `whoami` function (for nushell!)
This commit is contained in:
Daniel Hofstetter 2023-09-24 15:24:42 +02:00 committed by GitHub
commit 31d32e3ee2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,6 +5,8 @@
/* last synced with: whoami (GNU coreutils) 8.21 */
use std::ffi::OsString;
use clap::{crate_version, Command};
use uucore::display::println_verbatim;
@ -19,11 +21,16 @@ const USAGE: &str = help_usage!("whoami.md");
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
uu_app().try_get_matches_from(args)?;
let username = platform::get_username().map_err_context(|| "failed to get username".into())?;
let username = whoami()?;
println_verbatim(username).map_err_context(|| "failed to print username".into())?;
Ok(())
}
/// Get the current username
pub fn whoami() -> UResult<OsString> {
platform::get_username().map_err_context(|| "failed to get username".into())
}
pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(crate_version!())