Skip to main content

htb_cli/cli/
mod.rs

1pub mod auth;
2pub mod cache;
3pub mod challenges;
4pub mod ctf;
5pub mod machines;
6pub mod pwnbox;
7pub mod search;
8pub mod seasons;
9pub mod sherlocks;
10pub mod user;
11pub mod vpn;
12
13use std::path::PathBuf;
14
15use clap::{Parser, Subcommand};
16use clap_complete::Shell;
17
18#[derive(Parser)]
19#[command(
20    name = "htb",
21    version,
22    about = "Hack The Box CLI",
23    long_about = "Hack The Box CLI - interact with the HTB platform from your terminal.\n\nQuery machines, challenges, Sherlocks, and seasons. Spawn instances, submit flags, manage VPN connections.",
24    after_help = "Examples:\n  htb auth login                              Save your API token\n  htb machines list --os linux --difficulty easy   Filter machines\n  htb machines start Bedside                  Spawn a machine\n  htb challenges list --category Web          Browse web challenges\n  htb challenges submit 1018 'HTB{flag}'      Submit a challenge flag\n  htb vpn list                                Show VPN servers\n  htb user me                                 View your profile\n  htb search nmap                             Search across all content"
25)]
26pub struct Cli {
27    #[command(subcommand)]
28    pub command: Option<Command>,
29
30    #[arg(long, help = "Run as MCP server over stdin/stdout")]
31    pub mcp_stdio: bool,
32
33    #[arg(long, global = true, help = "Output as JSON")]
34    pub json: bool,
35
36    #[arg(long, global = true, help = "Disable colored output")]
37    pub no_color: bool,
38
39    #[arg(short, long, global = true, help = "Enable debug logging")]
40    pub verbose: bool,
41
42    #[arg(long, global = true, help = "Override config file path")]
43    pub config: Option<PathBuf>,
44
45    #[arg(long, global = true, help = "Bypass response cache")]
46    pub no_cache: bool,
47}
48
49#[derive(Subcommand)]
50pub enum Command {
51    /// Manage authentication
52    Auth {
53        #[command(subcommand)]
54        command: auth::AuthCommand,
55    },
56    /// Browse and interact with machines
57    Machines {
58        #[command(subcommand)]
59        command: machines::MachineCommand,
60    },
61    /// Browse and interact with challenges
62    Challenges {
63        #[command(subcommand)]
64        command: challenges::ChallengeCommand,
65    },
66    /// View seasons and rankings
67    Seasons {
68        #[command(subcommand)]
69        command: seasons::SeasonCommand,
70    },
71    /// Browse and interact with Sherlocks
72    Sherlocks {
73        #[command(subcommand)]
74        command: sherlocks::SherlockCommand,
75    },
76    /// Manage VPN connections
77    Vpn {
78        #[command(subcommand)]
79        command: vpn::VpnCommand,
80    },
81    /// View user profiles
82    User {
83        #[command(subcommand)]
84        command: user::UserCommand,
85    },
86    /// Check PwnBox status and usage
87    Pwnbox {
88        #[command(subcommand)]
89        command: pwnbox::PwnboxCommand,
90    },
91    /// Interact with CTF events and challenges
92    Ctf {
93        #[command(subcommand)]
94        command: ctf::CtfCommand,
95    },
96    /// Search across all content
97    Search {
98        /// Search query
99        query: String,
100    },
101    /// Manage response cache
102    Cache {
103        #[command(subcommand)]
104        command: cache::CacheCommand,
105    },
106    /// Generate shell completions
107    Completions {
108        /// Shell to generate completions for
109        shell: Shell,
110    },
111}