diff --git a/FULL_HELP_DOCS.md b/FULL_HELP_DOCS.md index 3445dec997..e3c5ddc4dd 100644 --- a/FULL_HELP_DOCS.md +++ b/FULL_HELP_DOCS.md @@ -2660,7 +2660,12 @@ Read cached action Print version information -**Usage:** `stellar version` +**Usage:** `stellar version [OPTIONS]` + +###### **Options:** + +* `--only-version` — Print only the version +* `--only-version-major` — Print only the major version diff --git a/cmd/soroban-cli/src/commands/version.rs b/cmd/soroban-cli/src/commands/version.rs index f785399e95..5874dfd07c 100644 --- a/cmd/soroban-cli/src/commands/version.rs +++ b/cmd/soroban-cli/src/commands/version.rs @@ -3,12 +3,25 @@ use std::fmt::Debug; #[derive(Parser, Debug, Clone)] #[group(skip)] -pub struct Cmd; +pub struct Cmd { + /// Print only the version. + #[arg(long)] + only_version: bool, + /// Print only the major version. + #[arg(long)] + only_version_major: bool, +} impl Cmd { #[allow(clippy::unused_self)] pub fn run(&self) { - println!("stellar {}", long()); + if self.only_version { + println!("{}", pkg()); + } else if self.only_version_major { + println!("{}", major()); + } else { + println!("stellar {}", long()); + } } } @@ -16,6 +29,10 @@ pub fn pkg() -> &'static str { env!("CARGO_PKG_VERSION") } +pub fn major() -> &'static str { + env!("CARGO_PKG_VERSION_MAJOR") +} + pub fn git() -> &'static str { env!("GIT_REVISION") }