cargo_gitv/cli.rs
1use clap::{Parser, Subcommand};
2
3#[derive(Parser)]
4#[clap(author, version, about, long_about = None)]
5pub struct Cli {
6 /// WHen we are called from cargo, the first argument is the subcommand. We just parse this for compatibility.
7 #[clap(value_parser)]
8 bin: Option<String>,
9 #[clap(subcommand)]
10 command: Command,
11}
12
13impl Cli {
14 pub fn called_from_cargo(&self) -> bool {
15 match &self.bin {
16 Some(bin) => bin == "gitv",
17 _ => false,
18 }
19 }
20
21 pub fn command(&self) -> &Command {
22 &self.command
23 }
24}
25
26#[derive(Subcommand)]
27pub enum Command {
28 /// Verify that the version computed from git is consistent with the Cargo version.
29 Verify,
30 /// Compute the current version based on git and Cargo metadata.
31 Version,
32}