shitbox/corebox/commands/logname/mod.rs
Nathan Fisher 06b88d2c24 Refactoring:
- Split into workspace crates
- Split into two binaries `corebox` and `hashbox`
- Add `mount` crate to workspace to prepare for third binary `utilbox`
2023-02-05 23:50:59 -05:00

28 lines
676 B
Rust

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: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
let logname = unsafe { CStr::from_ptr(libc::getlogin()) };
let logname = logname.to_str()?;
println!("{logname}");
Ok(())
}
fn path(&self) -> Option<shitbox::Path> {
Some(shitbox::Path::UsrBin)
}
}