From 4721f21368d947f13c62a0d9bd559b6105ccb674 Mon Sep 17 00:00:00 2001 From: Natsuki Ikeguchi Date: Tue, 2 Jan 2024 20:23:34 +0900 Subject: [PATCH] feat: Short flag for the version command --- src/cmd/version.rs | 15 ++++++++++++--- src/main.rs | 2 ++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/cmd/version.rs b/src/cmd/version.rs index 3dc6522..9fcf69c 100644 --- a/src/cmd/version.rs +++ b/src/cmd/version.rs @@ -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(()) } diff --git a/src/main.rs b/src/main.rs index 21a714b..b5c0ff4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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 {