Skip to content

Commit 247ebf1

Browse files
Add some options to the version command (#2013)
* add version display options to soroban-cli * add options to customize version output
1 parent 65fb81a commit 247ebf1

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

FULL_HELP_DOCS.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2660,7 +2660,12 @@ Read cached action
26602660

26612661
Print version information
26622662

2663-
**Usage:** `stellar version`
2663+
**Usage:** `stellar version [OPTIONS]`
2664+
2665+
###### **Options:**
2666+
2667+
* `--only-version` — Print only the version
2668+
* `--only-version-major` — Print only the major version
26642669

26652670

26662671

cmd/soroban-cli/src/commands/version.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,36 @@ use std::fmt::Debug;
33

44
#[derive(Parser, Debug, Clone)]
55
#[group(skip)]
6-
pub struct Cmd;
6+
pub struct Cmd {
7+
/// Print only the version.
8+
#[arg(long)]
9+
only_version: bool,
10+
/// Print only the major version.
11+
#[arg(long)]
12+
only_version_major: bool,
13+
}
714

815
impl Cmd {
916
#[allow(clippy::unused_self)]
1017
pub fn run(&self) {
11-
println!("stellar {}", long());
18+
if self.only_version {
19+
println!("{}", pkg());
20+
} else if self.only_version_major {
21+
println!("{}", major());
22+
} else {
23+
println!("stellar {}", long());
24+
}
1225
}
1326
}
1427

1528
pub fn pkg() -> &'static str {
1629
env!("CARGO_PKG_VERSION")
1730
}
1831

32+
pub fn major() -> &'static str {
33+
env!("CARGO_PKG_VERSION_MAJOR")
34+
}
35+
1936
pub fn git() -> &'static str {
2037
env!("GIT_REVISION")
2138
}

0 commit comments

Comments
 (0)