1use clap::{Args, ColorChoice, Parser, Subcommand};
2use clap_complete::Shell;
3
4#[derive(Parser)]
15#[command(name = "zql", version, about, author)]
16#[command(propagate_version = true)]
17pub struct Cli {
18 #[command(subcommand)]
19 pub command: Option<CommandKind>,
20
21 #[arg(long, value_name = "ALIAS", global = true)]
23 pub config: Option<String>,
24
25 #[arg(long = "table", short = 't', global = true)]
27 pub table: bool,
28
29 #[arg(long = "raw", short = 'r', global = true)]
31 pub raw: bool,
32
33 #[arg(long = "group", short = 'g', global = true)]
35 pub group: Option<String>,
36
37 #[arg(long = "flatten", short = 'f', global = true)]
39 pub flatten: bool,
40
41 #[arg(long = "verbose", short = 'v', global = true)]
43 pub verbose: bool,
44
45 #[arg(long = "color", global = true)]
47 pub color: Option<ColorChoice>,
48
49 pub queries: Vec<String>,
51
52 #[arg(long = "completion")]
54 pub shell: Option<Shell>,
55
56 #[cfg(debug_assertions)]
58 #[arg(long = "mock", default_missing_value = "")]
59 pub mock: Option<String>,
60}
61
62#[derive(Subcommand)]
63pub enum CommandKind {
64 Config(ConfigArgs),
66
67 Exec(ExecArgs),
69
70 Run(RunArgs),
72
73 Format(FormatArgs),
75
76 Show(ShowArgs),
78}
79
80#[derive(Args)]
81pub struct ConfigArgs {
82 #[command(subcommand)]
83 pub command: ConfigKind,
84}
85
86#[derive(Subcommand)]
87pub enum ConfigKind {
88 Add(ConfigAddArgs),
90
91 Remove(ConfigRemoveArgs),
93
94 Clear,
96
97 List,
99}
100
101#[derive(Args)]
102pub struct ConfigAddArgs {
103 pub alias: String,
105
106 pub odbc: Option<String>,
108
109 #[arg(long)]
111 pub default: bool,
112}
113
114#[derive(Args)]
115pub struct ConfigRemoveArgs {
116 pub alias: String,
118}
119
120#[derive(Args)]
121pub struct ExecArgs {
122 #[arg(from_global)]
124 pub config: Option<String>,
125
126 #[arg(from_global)]
128 pub table: bool,
129
130 #[arg(from_global)]
132 pub raw: bool,
133
134 #[arg(from_global)]
136 pub group: Option<String>,
137
138 #[arg(from_global)]
140 pub flatten: bool,
141
142 #[arg(from_global)]
144 pub verbose: bool,
145
146 #[arg(from_global)]
148 pub color: Option<ColorChoice>,
149
150 pub queries: Vec<String>,
152}
153
154#[derive(Args)]
155pub struct RunArgs {
156 #[arg(from_global)]
158 pub config: Option<String>,
159
160 #[arg(from_global)]
162 pub table: bool,
163
164 #[arg(from_global)]
166 pub raw: bool,
167
168 #[arg(from_global)]
170 pub group: Option<String>,
171
172 #[arg(from_global)]
174 pub flatten: bool,
175
176 #[arg(from_global)]
178 pub verbose: bool,
179
180 #[arg(from_global)]
182 pub color: Option<ColorChoice>,
183
184 pub paths: Vec<String>,
186}
187
188#[derive(Args)]
189pub struct FormatArgs {
190 #[arg(from_global)]
192 pub table: bool,
193
194 #[arg(long = "auto", short = 'a')]
196 pub auto: bool,
197
198 #[arg(from_global)]
200 pub raw: bool,
201
202 #[arg(from_global)]
204 pub group: Option<String>,
205
206 #[arg(from_global)]
208 pub flatten: bool,
209
210 #[arg(from_global)]
212 pub verbose: bool,
213
214 #[arg(from_global)]
216 pub color: Option<ColorChoice>,
217
218 pub paths: Vec<String>,
220}
221
222#[derive(Args)]
223pub struct ShowArgs {
224 #[command(subcommand)]
225 pub command: ShowKind,
226
227 #[arg(from_global)]
229 pub config: Option<String>,
230}
231
232#[derive(Subcommand)]
233pub enum ShowKind {
234 Databases,
236
237 Tables(SchemaArgs),
239
240 Columns(SchemaArgs),
242
243 Procedures(SchemaArgs),
245
246 Keywords,
248
249 Functions,
251}
252
253#[derive(Args)]
254pub struct SchemaArgs {
255 pub context: Option<String>,
257}