shitbox/corebox/commands/hostid/mod.rs
Nathan Fisher d248f7d17b Remove Default constraint on Cmd trait and begin removing
derive(Default) from applets
2023-04-17 23:27:57 -04:00

26 lines
691 B
Rust

use super::Cmd;
use clap::Command;
#[derive(Debug)]
pub struct Hostid;
impl Cmd for Hostid {
fn cli(&self) -> clap::Command {
Command::new("hostid")
.about("print the numeric identifier for the current host")
.author("Nathan Fisher")
.version(env!("CARGO_PKG_VERSION"))
}
fn run(&self, _matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
let hostid = unsafe { libc::gethostid() };
let hostid: String = format!("{hostid:x}").chars().skip(8).collect();
println!("{}", hostid);
Ok(())
}
fn path(&self) -> Option<shitbox::Path> {
Some(shitbox::Path::UsrBin)
}
}