1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use std::process::exit;

use clap::{arg, crate_version, Command};
use current_platform::CURRENT_PLATFORM;

pub fn cmdv(name: impl Into<clap::builder::Str>) -> Command {
  let cmd = Command::new(name)
    .disable_version_flag(true)
    .arg(arg!(-v --version ...))
    .arg(arg!(
        - -vv "version detail"
    ));

  let m = cmd.clone().ignore_errors(true).get_matches();

  let mut vv = m.get_one("vv") == Some(&true);

  if let Some(n) = m.get_one::<u8>("version") {
    let n = *n;
    if n > 0 {
      if n == 1 {
        println!(crate_version!());
        exit(0);
      } else {
        vv = true;
      }
    }
  }

  if vv {
    println!(
      r#"ver:{}
target:{}"#,
      crate_version!(),
      CURRENT_PLATFORM
    );
    exit(0);
  }

  cmd
}