Skip to content

Commit

Permalink
feat: Add whoami
Browse files Browse the repository at this point in the history
This commit adds the `whoami` command.
  • Loading branch information
AdamIsrael committed Nov 22, 2023
1 parent 61a43d4 commit 7608a22
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ members = [
"echo",
"env",
"wc",
"whoami",
]

[workspace.dependencies]
Expand Down
10 changes: 10 additions & 0 deletions whoami/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "whoami"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { workspace = true }
users = "0.11.0"
15 changes: 15 additions & 0 deletions whoami/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// Get the current user
///
/// Went the route of using the existing users crate rather than
/// re-implementing this via the libc crate.
use users::{get_current_uid, get_user_by_uid};

fn main() {
let user = get_user_by_uid(get_current_uid());
if let Some(u) = user {
let name = u.name().to_str();
if name.is_some() {
println!("{}", name.unwrap());
}
}
}

0 comments on commit 7608a22

Please sign in to comment.