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:
commit
31d32e3ee2
1 changed files with 8 additions and 1 deletions
|
@ -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!())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue