soroban_cli/commands/
version.rs

1use clap::Parser;
2use std::fmt::Debug;
3
4#[derive(Parser, Debug, Clone)]
5#[group(skip)]
6pub 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}
14
15impl Cmd {
16    #[allow(clippy::unused_self)]
17    pub fn run(&self) {
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        }
25    }
26}
27
28pub fn pkg() -> &'static str {
29    env!("CARGO_PKG_VERSION")
30}
31
32pub fn major() -> &'static str {
33    env!("CARGO_PKG_VERSION_MAJOR")
34}
35
36pub fn git() -> &'static str {
37    env!("GIT_REVISION")
38}
39
40pub fn long() -> String {
41    let xdr = stellar_xdr::VERSION;
42    [
43        format!("{} ({})", pkg(), git()),
44        format!(
45            "stellar-xdr {} ({})
46xdr curr ({})",
47            xdr.pkg, xdr.rev, xdr.xdr_curr,
48        ),
49    ]
50    .join("\n")
51}
52
53pub fn one_line() -> String {
54    let pkg = pkg();
55    let git = git();
56    format!("{pkg}#{git}")
57}