| 1 | mod cli; |
| 2 | mod commands; |
| 3 | mod config; |
| 4 | mod context; |
| 5 | mod git; |
| 6 | mod mcp; |
| 7 | mod ui; |
| 8 | |
| 9 | use { |
| 10 | anyhow::Result, |
| 11 | clap::Parser, |
| 12 | cli::{Cli, Command}, |
| 13 | console::style, |
| 14 | context::Ctx, |
| 15 | sigit_si_api::Client, |
| 16 | }; |
| 17 | |
| 18 | #[tokio::main] |
| 19 | async fn main() { |
| 20 | tracing_subscriber::fmt() |
| 21 | .with_env_filter(tracing_subscriber::EnvFilter::from_default_env()) |
| 22 | .with_writer(std::io::stderr) |
| 23 | .init(); |
| 24 | |
| 25 | if let Err(e) = run().await { |
| 26 | eprintln!("{} {:#}", style("✘").red(), e); |
| 27 | std::process::exit(1); |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | async fn run() -> Result<()> { |
| 32 | let cli = Cli::parse(); |
| 33 | |
| 34 | let mut client = Client::new(cli.environment)?; |
| 35 | if let Some(token) = config::read_token(cli.environment) { |
| 36 | client = client.with_token(token); |
| 37 | } |
| 38 | |
| 39 | let ctx = Ctx::new(client, cli.environment, cli.json); |
| 40 | |
| 41 | match cli.command { |
| 42 | Command::Auth(command) => commands::auth::run(&ctx, command).await, |
| 43 | Command::Me => commands::me::run(&ctx).await, |
| 44 | Command::Repo(command) => commands::repo::run(&ctx, command).await, |
| 45 | Command::Pr(command) => commands::pr::run(&ctx, command).await, |
| 46 | Command::Issue(command) => commands::issue::run(&ctx, command).await, |
| 47 | Command::Code(command) => commands::code::run(&ctx, command).await, |
| 48 | Command::Hook(command) => commands::hook::run(&ctx, command).await, |
| 49 | Command::Session(command) => commands::session::run(&ctx, command).await, |
| 50 | Command::Billing(command) => commands::billing::run(&ctx, command).await, |
| 51 | Command::Browse(args) => commands::browse::run(&ctx, args).await, |
| 52 | Command::Api(args) => commands::api::run(&ctx, args).await, |
| 53 | // Takes `ctx` by value: the server outlives the dispatch, serving |
| 54 | // tools over stdio until the client hangs up. |
| 55 | Command::Mcp(args) => mcp::run(ctx, args).await, |
| 56 | } |
| 57 | } |