Skip to main content

crates_docs/cli/
mod.rs

1//! CLI module
2//!
3//! Command-line interface for the Crates Docs MCP Server.
4
5mod commands;
6mod config_cmd;
7mod health_cmd;
8mod serve_cmd;
9mod test_cmd;
10mod version_cmd;
11
12use clap::Parser;
13use std::path::PathBuf;
14
15pub use commands::Commands;
16pub use config_cmd::run_config_command;
17pub use health_cmd::run_health_command;
18pub use serve_cmd::run_serve_command;
19pub use test_cmd::run_test_command;
20pub use version_cmd::run_version_command;
21
22/// CLI configuration
23#[derive(Parser)]
24#[command(name = "crates-docs")]
25#[command(version = env!("CARGO_PKG_VERSION"))]
26#[command(about = "High-performance Rust crate documentation query MCP server", long_about = None)]
27pub struct Cli {
28    /// CLI command to execute
29    #[command(subcommand)]
30    pub command: Commands,
31
32    /// Configuration file path
33    #[arg(short, long, global = true, default_value = "config.toml")]
34    pub config: PathBuf,
35
36    /// Enable debug logging
37    #[arg(short, long, global = true)]
38    pub debug: bool,
39
40    /// Enable verbose output
41    #[arg(short, long, global = true)]
42    pub verbose: bool,
43}
44
45/// Run the CLI application
46pub async fn run(cli: Cli) -> Result<(), Box<dyn std::error::Error>> {
47    match cli.command {
48        Commands::Serve {
49            mode,
50            host,
51            port,
52            enable_oauth,
53            oauth_client_id,
54            oauth_client_secret,
55            oauth_redirect_uri,
56        } => {
57            run_serve_command(
58                &cli.config,
59                cli.debug,
60                mode,
61                host,
62                port,
63                enable_oauth,
64                oauth_client_id,
65                oauth_client_secret,
66                oauth_redirect_uri,
67            )
68            .await?;
69        }
70        Commands::Config { output, force } => {
71            run_config_command(&output, force)?;
72        }
73        Commands::Test {
74            tool,
75            crate_name,
76            item_path,
77            query,
78            version,
79            limit,
80            format,
81        } => {
82            run_test_command(
83                &tool,
84                crate_name.as_deref(),
85                item_path.as_deref(),
86                query.as_deref(),
87                version.as_deref(),
88                limit,
89                &format,
90            )
91            .await?;
92        }
93        Commands::Health {
94            check_type,
95            verbose,
96        } => {
97            run_health_command(&check_type, verbose).await?;
98        }
99        Commands::Version => {
100            run_version_command();
101        }
102    }
103
104    Ok(())
105}