diff --git a/README.md b/README.md index cd0e33b..75e4a0a 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ code between applets, making for an overall smaller binary. - base64 - basename - bootstrap +- chgrp - chmod - chown - clear @@ -35,9 +36,12 @@ code between applets, making for an overall smaller binary. - hostname - link - mkfifo +- mknod - mountpoint - nologin - nproc +- printenv +- pwd - rev - rm - rmdir diff --git a/src/cmd/logname/mod.rs b/src/cmd/logname/mod.rs new file mode 100644 index 0000000..a891038 --- /dev/null +++ b/src/cmd/logname/mod.rs @@ -0,0 +1,27 @@ +use std::ffi::CStr; + +use super::Cmd; +use clap::Command; + +#[derive(Debug, Default)] +pub struct Logname; + +impl Cmd for Logname { + fn cli(&self) -> clap::Command { + Command::new("logname") + .about("print user's login name") + .author("Nathan Fisher") + .version(env!("CARGO_PKG_VERSION")) + } + + fn run(&self, _matches: Option<&clap::ArgMatches>) -> Result<(), Box> { + let logname = unsafe { CStr::from_ptr(libc::getlogin()) }; + let logname = logname.to_str()?; + println!("{logname}"); + Ok(()) + } + + fn path(&self) -> Option { + Some(crate::Path::UsrBin) + } +} diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index 5811bf3..ccb61d6 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -24,6 +24,7 @@ mod head; mod hostname; mod link; mod ln; +mod logname; mod ls; mod mkfifo; mod mknod; @@ -81,6 +82,7 @@ pub fn get(name: &str) -> Option> { "groups" => Some(Box::new(groups::Groups::default())), "head" => Some(Box::new(head::Head::default())), "link" => Some(Box::new(link::Link::default())), + "logname" => Some(Box::new(logname::Logname::default())), "mkfifo" => Some(Box::new(mkfifo::MkFifo::default())), "mknod" => Some(Box::new(mknod::MkNod::default())), "mountpoint" => Some(Box::new(mountpoint::Mountpoint::default())), @@ -103,13 +105,13 @@ pub fn get(name: &str) -> Option> { } } -pub static COMMANDS: [&str; 36] = [ +pub static COMMANDS: [&str; 37] = [ "base32", "base64", "basename", "bootstrap", - "chmod", "chgrp", + "chmod", "chown", "clear", "cut", @@ -122,6 +124,7 @@ pub static COMMANDS: [&str; 36] = [ "head", "hostname", "link", + "logname", "mkfifo", "mknod", "mountpoint",