aardvark_dns/commands/
version.rs1use clap::Parser;
2use std::fmt;
3
4#[derive(Parser, Debug)]
5pub struct Version {}
6
7#[derive(Debug)]
8struct Info {
9 version: &'static str,
10 commit: &'static str,
11 build_time: &'static str,
12 target: &'static str,
13}
14
15impl fmt::Display for Info {
17 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18 write!(
19 f,
20 "{{
21 \"version\": \"{}\",
22 \"commit\": \"{}\",
23 \"build_time\": \"{}\",
24 \"target\": \"{}\"
25}}",
26 self.version, self.commit, self.build_time, self.target
27 )
28 }
29}
30
31impl Version {
32 pub fn exec(&self) {
33 let info = Info {
34 version: env!("CARGO_PKG_VERSION"),
35 commit: env!("GIT_COMMIT"),
36 build_time: env!("BUILD_TIMESTAMP"),
37 target: env!("BUILD_TARGET"),
38 };
39 println!("{info}");
40 }
41}