Skip to main content

sc/cli/commands/
version.rs

1//! Version command implementation.
2
3use crate::error::Result;
4use serde::Serialize;
5
6#[derive(Serialize)]
7struct VersionOutput<'a> {
8    version: &'a str,
9    build: &'a str,
10}
11
12/// Execute the version command.
13///
14/// # Errors
15///
16/// Returns an error if JSON serialization fails.
17pub fn execute(json: bool) -> Result<()> {
18    let version = env!("CARGO_PKG_VERSION");
19    let build = if cfg!(debug_assertions) {
20        "dev"
21    } else {
22        "release"
23    };
24
25    if json {
26        let output = VersionOutput { version, build };
27        let payload = serde_json::to_string(&output)?;
28        println!("{payload}");
29        return Ok(());
30    }
31
32    println!("sc version {version} ({build})");
33    Ok(())
34}