| 1 |
|
| 2 |
|
| 3 |
|
| 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 |
|
| 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 |
|
| 25 |
Version { |
| 26 |
|
| 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 |
} |