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::Serve(args) => handlers::serve::run_serve(&cli, args).await,
26        Commands::Mcp { command } => handlers::mcp::run_mcp(&ctx, command).await,
27        Commands::Sessions { .. }
28        | Commands::Init
29        | Commands::Pr { .. }
30        | Commands::Eval(_)
31        | Commands::Execpolicy(_)
32        | Commands::Features(_)
33        | Commands::Resume { .. }
34        | Commands::Fork { .. } => {
35            bail!("This subcommand is not available in headless CLI yet — see TUI方案.md")
36        }
37        Commands::Sandbox(args) => handlers::sandbox::run(args.command),
38    }
39}