athena_cli/
cli.rs

1use clap::{Args, Parser, Subcommand};
2use humantime::parse_duration;
3use std::time::Duration;
4
5// Shared AWS arguments used by multiple commands
6#[derive(Args, Clone, Default)]
7pub struct AwsArgs {
8    /// AWS Profile name
9    #[arg(short, long, global = true)]
10    pub profile: Option<String>,
11
12    /// Workgroup name
13    #[arg(short, long, global = true)]
14    pub workgroup: Option<String>,
15
16    /// Database name
17    #[arg(short, long, global = true)]
18    pub database: Option<String>,
19
20    /// Catalog name
21    #[arg(long, global = true)]
22    pub catalog: Option<String>,
23
24    /// AWS Region
25    #[arg(long, global = true)]
26    pub region: Option<String>,
27
28    /// S3 output location (for query results)
29    #[arg(long, global = true)]
30    pub output_location: Option<String>,
31}
32
33// Global display settings
34#[derive(Args, Clone, Default)]
35pub struct DisplayArgs {
36    /// Suppress detailed output
37    #[arg(short, long, global = true)]
38    pub quiet: bool,
39}
40
41// Shared arguments for commands that support file output
42#[derive(Args, Clone)]
43pub struct OutputArgs {
44    /// Output directory for results
45    #[arg(short, long)]
46    pub output: Option<String>,
47}
48
49#[derive(Parser)]
50#[command(author, version, about, long_about = None)]
51pub struct Cli {
52    #[command(subcommand)]
53    pub command: Commands,
54
55    #[command(flatten)]
56    pub aws: AwsArgs,
57
58    #[command(flatten)]
59    pub display: DisplayArgs,
60}
61
62#[derive(Subcommand)]
63pub enum Commands {
64    /// Execute a query
65    Query(QueryArgs),
66
67    /// Database operations
68    Database {
69        #[command(subcommand)]
70        command: DatabaseCommands,
71    },
72
73    /// Table operations
74    Table {
75        #[command(subcommand)]
76        command: TableCommands,
77    },
78
79    /// Workgroup operations
80    Workgroup {
81        #[command(subcommand)]
82        command: WorkgroupCommands,
83    },
84
85    /// Show query history
86    History(HistoryArgs),
87
88    /// Inspect details of a specific query
89    Inspect(InspectArgs),
90
91    /// Download query results (shortcut for 'inspect -o')
92    #[command(alias = "dl")] // Optional: add even shorter alias
93    Download(DownloadArgs),
94}
95
96#[derive(Subcommand)]
97pub enum DatabaseCommands {
98    /// List available databases
99    List(DatabaseArgs),
100}
101
102#[derive(Subcommand)]
103pub enum TableCommands {
104    /// List tables in a database
105    List(TableArgs),
106
107    /// Describe table structure with columns and partitions
108    Describe(DescribeTableArgs),
109}
110
111#[derive(Subcommand)]
112pub enum WorkgroupCommands {
113    /// List workgroups
114    List(WorkgroupArgs),
115}
116
117#[derive(Args, Clone)]
118pub struct QueryArgs {
119    #[command(flatten)]
120    pub aws: AwsArgs,
121
122    /// SQL query to execute
123    pub query: String,
124
125    /// Query reuse time (e.g., "10m", "2h", "1h30m")
126    #[arg(short = 'r', long, value_parser = parse_duration, default_value = "60m")]
127    pub reuse_time: Duration,
128}
129
130#[derive(Args, Clone)]
131pub struct DatabaseArgs {
132    // Empty - will use global catalog from AwsArgs
133    #[command(flatten)]
134    pub aws: AwsArgs,
135}
136
137#[derive(Args, Clone)]
138pub struct TableArgs {
139    /// Database name (overrides global settings)
140    #[arg(short = 'n', long)]
141    pub db: Option<String>,
142
143    /// Filter table names by pattern (e.g. "pp_*" for tables starting with pp_)
144    #[arg(short, long)]
145    pub filter: Option<String>,
146
147    /// Maximum number of tables to list
148    #[arg(short, long, default_value = "50")]
149    pub limit: i32,
150}
151
152#[derive(Args, Clone)]
153pub struct DescribeTableArgs {
154    /// Table identifier (can be 'database.table' or just 'table')
155    pub table: String,
156
157    /// Database name (alternative to using 'database.table' format)
158    #[arg(short = 'n', long)]
159    pub db: Option<String>,
160}
161
162#[derive(Args, Clone)]
163pub struct WorkgroupArgs {
164    /// Maximum number of workgroups to list
165    #[arg(short, long, default_value = "50")]
166    pub limit: i32,
167}
168
169#[derive(Args, Clone)]
170pub struct HistoryArgs {
171    /// Maximum number of history items to show (overrides config)
172    #[arg(short, long)]
173    pub limit: Option<i32>,
174
175    /// Show only queries with specific status (SUCCEEDED, FAILED, CANCELLED)
176    #[arg(short, long)]
177    pub status: Option<String>,
178}
179
180// For commands that support output
181#[derive(Args, Clone)]
182pub struct InspectArgs {
183    /// Query execution ID to inspect
184    pub query_id: String,
185
186    /// Output directory for query results (e.g., "." for current directory)
187    #[arg(short, long)]
188    pub output: Option<String>,
189
190    /// Quiet mode - only output the downloaded file path
191    #[arg(short, long)]
192    pub quiet: bool,
193}
194
195#[derive(Args, Clone)]
196pub struct DownloadArgs {
197    /// Query execution ID
198    pub query_id: String,
199
200    /// Output directory for results
201    #[arg(short, long, default_value = ".")]
202    pub output: Option<String>,
203}