OXYGENHUB
# 366e358ff5e7 spectra / src / cli / mod.rs
1.5 KiB · Rust · last changed Project skeleton in Oxygen's shape: workspace, deps/oxygen pinned, make check, version, deps-check (#1) 2 days ago source blame history raw
1
//! The `spectra` command line (spec §19). Output follows `oxy`: colour and
2
//! glyphs on a UTF-8 terminal, plain when piped, with `--plain` or with
3
//! `NO_COLOR`; `--json` prints one document on stdout and nothing else.
4
5
pub mod format;
6
pub mod json;
7
pub mod ui;
8
9
use anyhow::Result;
10
use clap::{Parser, Subcommand};
11
12
#[derive(Parser)]
13
#[command(name = "spectra", version = env!("SPECTRA_VERSION_LONG"), about = "A control plane for AI coding agents")]
14
pub struct Cli {
15
    /// Plain output: no colour or glyphs (also NO_COLOR, or when not a terminal)
16
    #[arg(long, global = true)]
17
    pub plain: bool,
18
    #[command(subcommand)]
19
    pub command: Command,
20
}
21
22
#[derive(Subcommand)]
23
pub enum Command {
24
    /// The version and build of this binary
25
    Version {
26
        /// Machine-readable output
27
        #[arg(long)]
28
        json: bool,
29
    },
30
}
31
32
pub fn run() -> Result<i32> {
33
    let cli = Cli::parse();
34
    ui::init(cli.plain);
35
    match cli.command {
36
        Command::Version { json } => version(json),
37
    }
38
}
39
40
fn version(as_json: bool) -> Result<i32> {
41
    if as_json {
42
        println!(
43
            "{}",
44
            serde_json::json!({
45
                "version": env!("CARGO_PKG_VERSION"),
46
                "build": env!("SPECTRA_BUILD_ID"),
47
                "mcp_protocol_versions": spectra_mcp::PROTOCOL_VERSIONS,
48
                "ledger_format": spectra_core::LEDGER_FORMAT,
49
            })
50
        );
51
    } else {
52
        println!("spectra {}", env!("SPECTRA_VERSION_LONG"));
53
    }
54
    Ok(0)
55
}