Skip to main content

cratedex/
cli.rs

1//! Defines the command-line interface for Cratedex.
2
3use clap::{Parser, Subcommand};
4
5#[derive(Parser, Debug)]
6#[command(
7    author,
8    version,
9    about = "A Model Context Protocol Server for the Rust Cargo toolchain.",
10    subcommand_required = false,
11    arg_required_else_help = false,
12    disable_help_subcommand = true
13)]
14pub struct Cli {
15    #[command(subcommand)]
16    pub command: Option<Commands>,
17}
18
19#[derive(Subcommand, Debug)]
20pub enum Commands {
21    /// Starts the Cratedex server.
22    Server,
23    /// Installs optional prerequisites like cargo-outdated and cargo-audit.
24    Setup,
25    /// Install cratedex as a systemd service (HTTP transport).
26    InstallService {
27        /// HTTP bind address.
28        #[arg(long, default_value = "127.0.0.1")]
29        host: String,
30        /// HTTP bind port.
31        #[arg(long, default_value_t = 3737)]
32        port: u16,
33        /// Enable loginctl linger so the service survives logout.
34        #[arg(long, conflicts_with = "system")]
35        linger: bool,
36        /// Allow binding to non-loopback addresses (only enable behind TLS+auth reverse proxy).
37        #[arg(long)]
38        allow_remote: bool,
39        /// Install as a system-level service (writes to /etc/systemd/system,
40        /// managed with plain `systemctl`). Requires root.
41        #[arg(long, conflicts_with = "linger")]
42        system: bool,
43        /// User account the system service runs as (default: $SUDO_USER or current user).
44        #[arg(long, default_value = None, requires = "system")]
45        run_as: Option<String>,
46    },
47    /// Remove the cratedex systemd service.
48    RemoveService {
49        /// Remove the system-level service (from /etc/systemd/system). Requires root.
50        #[arg(long)]
51        system: bool,
52    },
53}