OXYGENHUB

Coverage / src/cli/mod.rs 0.0%

0 of 22 lines run, 0 of 2 functions · run #2 on main · run missed

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
320×
pub fn run() -> Result<i32> {
330×
    let cli = Cli::parse();
340×
    ui::init(cli.plain);
350×
    match cli.command {
360×
        Command::Version { json } => version(json),
37
    }
380×
}
39
400×
fn version(as_json: bool) -> Result<i32> {
410×
    if as_json {
420×
        println!(
430×
            "{}",
440×
            serde_json::json!({
450×
                "version": env!("CARGO_PKG_VERSION"),
460×
                "build": env!("SPECTRA_BUILD_ID"),
470×
                "mcp_protocol_versions": spectra_mcp::PROTOCOL_VERSIONS,
480×
                "ledger_format": spectra_core::LEDGER_FORMAT,
490×
            })
500×
        );
510×
    } else {
520×
        println!("spectra {}", env!("SPECTRA_VERSION_LONG"));
530×
    }
540×
    Ok(0)
550×
}