Skip to content

Commit 20bfeb3

Browse files
authored
Merge pull request #11343 from gitbutlerapp/print-version-flag-but-cli
Add --version flag support for but CLI
2 parents f553b7b + 6e39e7d commit 20bfeb3

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

crates/but/src/args/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use std::path::PathBuf;
1010

1111
#[derive(Debug, clap::Parser)]
12-
#[clap(name = "but", about = "A GitButler CLI tool", version = option_env!("GIX_VERSION"))]
12+
#[clap(name = "but", about = "A GitButler CLI tool", version = option_env!("VERSION").unwrap_or("dev"))]
1313
pub struct Args {
1414
/// Enable tracing for debug and performance information printed to stderr.
1515
#[clap(short = 't', long, action = clap::ArgAction::Count, hide = true, env = "BUT_TRACE")]

crates/but/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ type LegacyProject = gitbutler_project::Project;
4848
pub async fn handle_args(args: impl Iterator<Item = OsString>) -> Result<()> {
4949
let args: Vec<_> = args.collect();
5050

51+
// Check if version is requested
52+
if args.iter().any(|arg| arg == "--version" || arg == "-V") {
53+
let version = option_env!("VERSION").unwrap_or("dev");
54+
println!("but {}", version);
55+
return Ok(());
56+
}
57+
5158
// Check if help is requested with no subcommand
5259
if args.len() == 1 || args.iter().any(|arg| arg == "--help" || arg == "-h") && args.len() == 2 {
5360
let mut out = OutputChannel::new_with_pager(OutputFormat::Human);

0 commit comments

Comments
 (0)