2023-01-23 10:17:17 -05:00
|
|
|
use super::Cmd;
|
|
|
|
use clap::Command;
|
|
|
|
|
2023-04-17 23:27:57 -04:00
|
|
|
#[derive(Debug)]
|
2023-01-23 10:17:17 -05:00
|
|
|
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"))
|
|
|
|
}
|
|
|
|
|
2023-02-04 08:54:27 -05:00
|
|
|
fn run(&self, _matches: &clap::ArgMatches) -> Result<(), Box<dyn std::error::Error>> {
|
2023-01-24 00:51:36 -05:00
|
|
|
let hostid = unsafe { libc::gethostid() };
|
2023-01-23 10:17:17 -05:00
|
|
|
let hostid: String = format!("{hostid:x}").chars().skip(8).collect();
|
|
|
|
println!("{}", hostid);
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2023-02-05 23:50:59 -05:00
|
|
|
fn path(&self) -> Option<shitbox::Path> {
|
|
|
|
Some(shitbox::Path::UsrBin)
|
2023-01-23 10:17:17 -05:00
|
|
|
}
|
|
|
|
}
|