Skip to main content

zagens_runtime/cli/
dispatch.rs

1use anyhow::{Result, bail};
2
3use crate::cli::args::{Cli, Commands};
4use crate::cli::context::load_cli_context;
5use crate::cli::handlers;
6
7pub async fn run(cli: Cli) -> Result<()> {
8    crate::logging::set_verbose(cli.verbose || crate::logging::env_requests_verbose_logging());
9    let ctx = load_cli_context(&cli)?;
10    let config_path = cli.config.as_deref();
11
12    match cli.command.clone().expect("subcommand checked in main") {
13        Commands::Doctor(args) => handlers::doctor::run(&ctx, config_path, args).await,
14        Commands::Setup(args) => handlers::setup::run(&ctx, args),
15        Commands::Completions { shell } => {
16            handlers::completions::run(shell);
17            Ok(())
18        }
19        Commands::Login { api_key } => handlers::login::run_login(api_key),
20        Commands::Logout => handlers::login::run_logout(),
21        Commands::Models(args) => handlers::models::run(&ctx, args).await,
22        Commands::Exec(args) => handlers::exec::run(&cli, &ctx, args).await,
23        Commands::Review(args) => handlers::review::run_review(&ctx, args).await,
24        Commands::Apply(args) => handlers::review::run_apply(&ctx.workspace, args),
25        Commands::CoverageGate(args) => {
26            let code = handlers::coverage_gate::run(args)?;
27            std::process::exit(if code == std::process::ExitCode::SUCCESS {
28                0
29            } else {
30                1
31            });
32        }
33        Commands::Serve(args) => handlers::serve::run_serve(&cli, args).await,
34        Commands::Mcp { command } => handlers::mcp::run_mcp(&ctx, command).await,
35        Commands::Sessions { .. }
36        | Commands::Init
37        | Commands::Pr { .. }
38        | Commands::Eval(_)
39        | Commands::Execpolicy(_)
40        | Commands::Features(_)
41        | Commands::Resume { .. }
42        | Commands::Fork { .. } => {
43            bail!("This subcommand is not available in headless CLI yet — see TUI方案.md")
44        }
45        Commands::Sandbox(args) => handlers::sandbox::run(args.command),
46    }
47}