2023-01-21 19:34:02 -05:00
|
|
|
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"))
|
|
|
|
}
|
|
|
|
|
2023-02-04 08:54:27 -05:00
|
|
|
fn run(&self, _matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
2023-01-21 19:34:02 -05:00
|
|
|
let logname = unsafe { CStr::from_ptr(libc::getlogin()) };
|
|
|
|
let logname = logname.to_str()?;
|
|
|
|
println!("{logname}");
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
fn path(&self) -> Option<crate::Path> {
|
|
|
|
Some(crate::Path::UsrBin)
|
|
|
|
}
|
|
|
|
}
|