Skip to content

Commit

Permalink
feat: Short flag for the version command
Browse files Browse the repository at this point in the history
  • Loading branch information
siketyan committed Jan 2, 2024
1 parent 8b0e57a commit 4721f21
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/cmd/version.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
use anyhow::Result;
use clap::Parser;

use crate::BUILD_INFO;
use crate::{BUILD_INFO, VERSION};

#[derive(Debug, Parser)]
pub struct Cmd {}
pub struct Cmd {
#[clap(short, long)]
short: bool,
}

impl Cmd {
pub fn run(self) -> Result<()> {
println!("{}", BUILD_INFO);
println!(
"{}",
match self.short {
true => VERSION,
_ => BUILD_INFO,
},
);

Ok(())
}
Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const BUILD_INFO: &str = build_info::format!(
$.timestamp,
);

const VERSION: &str = build_info::format!("{}", $.crate_info.version);

#[tokio::main]
async fn main() {
if let Err(e) = Cli::parse().run().await {
Expand Down

0 comments on commit 4721f21

Please sign in to comment.