1
use std::fmt;
2

            
3
use clap::Args;
4

            
5
const VERSION: &str = env!("CARGO_PKG_VERSION");
6
const BUILD_HASH: &str = env!("BUILD_HASH");
7

            
8
#[derive(Args, Clone, Copy, Debug)]
9
pub struct VersionFlag {
10
    #[arg(
11
        long,
12
        global = true,
13
        default_value_t = false,
14
        help = "Print the version of this tool"
15
    )]
16
    version: bool,
17
}
18

            
19
impl From<VersionFlag> for bool {
20
    fn from(val: VersionFlag) -> Self {
21
        val.version
22
    }
23
}
24

            
25
pub struct Version;
26

            
27
impl fmt::Display for Version {
28
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29
        write!(f, "{}-{}", VERSION, &BUILD_HASH[..8])
30
    }
31
}