Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add whoami #22

Merged
merged 3 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,5 @@ This began as, and continues to be, a learning exercise to better understand the
| vdir | |
| wc | :white_check_mark: |
| who | |
| whoami | |
| whoami | :white_check_mark: |
| yes | |
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());
}
}
}
Loading