1use clap::{Parser, Subcommand};
2
3#[derive(Parser, Debug)]
5#[command(author, version, about, long_about = None, disable_help_subcommand = true)]
6pub struct Cli {
7 #[arg(long, global = true, default_value = "text")]
9 pub output: String,
10
11 #[arg(long, global = true)]
13 pub non_interactive: bool,
14
15 #[arg(long, global = true)]
17 pub trace_id: Option<String>,
18
19 #[arg(long, global = true, default_value = "text")]
21 pub log_format: String,
22
23 #[arg(long, global = true)]
25 pub max_cost_credits: Option<u32>,
26
27 #[arg(long, global = true)]
29 pub budget_daily_credits: Option<u32>,
30
31 #[arg(long, global = true)]
33 pub dry_run: bool,
34
35 #[command(subcommand)]
36 pub command: Option<Commands>,
37}
38
39#[derive(Subcommand, Debug)]
40pub enum Commands {
41 Commands,
43
44 Schema {
46 #[arg(long)]
48 command: String,
49 },
50
51 Help {
53 command: String,
55 },
56
57 DemoInteractive,
59
60 Tweets {
62 #[command(subcommand)]
63 command: TweetsCommands,
64 },
65
66 Auth {
68 #[command(subcommand)]
69 command: AuthCommands,
70 },
71
72 Billing {
74 #[command(subcommand)]
75 command: BillingCommands,
76 },
77
78 Doctor,
80}
81
82#[derive(Subcommand, Debug)]
83pub enum TweetsCommands {
84 Create {
86 text: String,
88
89 #[arg(long)]
91 client_request_id: Option<String>,
92
93 #[arg(long, default_value = "return")]
95 if_exists: String,
96 },
97
98 List {
100 #[arg(long)]
102 fields: Option<String>,
103
104 #[arg(long)]
106 limit: Option<usize>,
107
108 #[arg(long)]
110 cursor: Option<String>,
111 },
112}
113
114#[derive(Subcommand, Debug)]
115pub enum AuthCommands {
116 Status,
118
119 Export,
121
122 Import {
124 data: String,
126
127 #[arg(long)]
129 dry_run: bool,
130 },
131}
132
133#[derive(Subcommand, Debug)]
134pub enum BillingCommands {
135 Estimate {
137 operation: String,
139
140 #[arg(long)]
142 text: Option<String>,
143 },
144
145 Report,
147}
148
149#[cfg(test)]
150mod tests {
151 use super::*;
152
153 #[test]
154 fn test_cli_parsing() {
155 let cli = Cli::parse_from(["xcom-rs", "commands"]);
156 assert!(matches!(cli.command, Some(Commands::Commands)));
157 }
158
159 #[test]
160 fn test_cli_with_output_format() {
161 let cli = Cli::parse_from(["xcom-rs", "--output", "json", "commands"]);
162 assert_eq!(cli.output, "json");
163 }
164
165 #[test]
166 fn test_cli_with_trace_id() {
167 let cli = Cli::parse_from(["xcom-rs", "--trace-id", "test-123", "commands"]);
168 assert_eq!(cli.trace_id, Some("test-123".to_string()));
169 }
170
171 #[test]
172 fn test_schema_command() {
173 let cli = Cli::parse_from(["xcom-rs", "schema", "--command", "commands"]);
174 if let Some(Commands::Schema { command, .. }) = cli.command {
175 assert_eq!(command, "commands");
176 } else {
177 panic!("Expected Schema command");
178 }
179 }
180
181 #[test]
182 fn test_help_command() {
183 let cli = Cli::parse_from(["xcom-rs", "help", "commands"]);
184 if let Some(Commands::Help { command }) = cli.command {
185 assert_eq!(command, "commands");
186 } else {
187 panic!("Expected Help command");
188 }
189 }
190
191 #[test]
192 fn test_cli_without_subcommand() {
193 let cli = Cli::parse_from(["xcom-rs"]);
194 assert!(cli.command.is_none());
195 }
196}