Skip to main content

thundra/
cli.rs

1use crate::config::{HttpMethod, OutputFormat};
2use clap::{Parser, Subcommand};
3use clap_complete::Shell;
4
5/// Thundra is an API benchmark tool built with Rust
6#[derive(Parser)]
7#[command(name = "thundra")]
8#[command(version, about = "Thundra is an API benchmark tool built with Rust")]
9pub struct Cli {
10    #[command(subcommand)]
11    pub command: Option<Commands>,
12
13    /// Target URL to bench
14    pub url: Option<String>,
15
16    /// HTTP method
17    #[arg(short, long, value_enum, default_value = "get")]
18    pub method: HttpMethod,
19
20    /// Number of concurrent connections
21    #[arg(short, long, default_value_t = 10)]
22    pub concurrency: usize,
23
24    /// Total number of requests
25    #[arg(short = 'n', long, conflicts_with = "duration")]
26    pub requests: Option<usize>,
27
28    /// Test duration (e.g. 10s, 1m)
29    #[arg(short, long, conflicts_with = "requests")]
30    pub duration: Option<String>,
31
32    /// HTTP header (repeatable)
33    #[arg(short = 'H', long = "header")]
34    pub headers: Vec<String>,
35
36    /// Request body
37    #[arg(short, long)]
38    pub body: Option<String>,
39
40    /// Request timeout in seconds
41    #[arg(short, long, default_value_t = 30)]
42    pub timeout: u64,
43
44    /// Target requests per second (rate limit)
45    #[arg(short = 'r', long)]
46    pub rate: Option<u64>,
47
48    /// Skip TLS certificate verification
49    #[arg(short = 'k', long)]
50    pub insecure: bool,
51
52    /// Output serialized into provided format
53    #[arg(short = 'o', long, value_enum, default_value_t = OutputFormat::Text)]
54    pub output: OutputFormat,
55}
56
57#[derive(Subcommand)]
58pub enum Commands {
59    /// Generate shell completion scripts
60    Completions {
61        /// The shell to generate completions for
62        #[arg(value_enum)]
63        shell: Shell,
64    },
65}