1pub mod config;
8pub mod conn;
9pub mod data;
10pub mod globals;
11pub mod history;
12pub mod meta;
13pub mod query;
14pub mod schema;
15pub mod server;
16
17use clap::{Parser, Subcommand};
18
19#[derive(Debug, Parser)]
23#[command(
24 name = "mariadb-cli",
25 version,
26 about = "One-shot agent-native command line client for MariaDB servers",
27 long_about = None,
28 propagate_version = true,
29 disable_help_subcommand = true,
30)]
31pub struct Cli {
32 #[command(flatten)]
34 pub globals: globals::GlobalFlags,
35
36 #[command(subcommand)]
38 pub command: Command,
39}
40
41#[derive(Debug, Clone, Subcommand)]
43pub enum Command {
44 #[command(subcommand)]
46 Conn(conn::ConnCommand),
47
48 #[command(subcommand)]
50 Schema(schema::SchemaCommand),
51
52 #[command(subcommand)]
54 Query(query::QueryCommand),
55
56 #[command(subcommand)]
58 Data(data::DataCommand),
59
60 #[command(subcommand)]
62 Server(server::ServerCommand),
63
64 #[command(subcommand)]
66 History(history::HistoryCommand),
67
68 #[command(subcommand)]
70 Config(config::ConfigCommand),
71
72 #[command(subcommand)]
74 Meta(meta::MetaCommand),
75}
76
77impl Command {
78 #[must_use]
83 pub const fn published_name(&self) -> &'static str {
84 match self {
85 Self::Conn(inner) => inner.published_name(),
86 Self::Schema(inner) => inner.published_name(),
87 Self::Query(inner) => inner.published_name(),
88 Self::Data(inner) => inner.published_name(),
89 Self::Server(inner) => inner.published_name(),
90 Self::History(inner) => inner.published_name(),
91 Self::Config(inner) => inner.published_name(),
92 Self::Meta(inner) => inner.published_name(),
93 }
94 }
95}
96
97impl conn::ConnCommand {
98 #[must_use]
100 pub const fn published_name(&self) -> &'static str {
101 match self {
102 Self::Add(_) => "conn add",
103 Self::List => "conn list",
104 Self::Show(_) => "conn show",
105 Self::Edit(_) => "conn edit",
106 Self::Remove(_) => "conn remove",
107 Self::Test(_) => "conn test",
108 Self::Default(_) => "conn default",
109 }
110 }
111}
112
113impl schema::SchemaCommand {
114 #[must_use]
116 pub const fn published_name(&self) -> &'static str {
117 match self {
118 Self::Map(_) => "schema map",
119 Self::Databases => "schema databases",
120 Self::Tables(_) => "schema tables",
121 Self::Columns(_) => "schema columns",
122 Self::Keys(_) => "schema keys",
123 Self::Indexes(_) => "schema indexes",
124 Self::Checks(_) => "schema checks",
125 Self::Views(_) => "schema views",
126 Self::Routines(_) => "schema routines",
127 Self::Triggers(_) => "schema triggers",
128 Self::Events(_) => "schema events",
129 Self::Sequences(_) => "schema sequences",
130 Self::Partitions(_) => "schema partitions",
131 Self::Search(_) => "schema search",
132 Self::Stats(_) => "schema stats",
133 Self::Ddl(_) => "schema ddl",
134 Self::Count(_) => "schema count",
135 Self::Size(_) => "schema size",
136 Self::Grants => "schema grants",
137 }
138 }
139}
140
141impl query::QueryCommand {
142 #[must_use]
144 pub const fn published_name(&self) -> &'static str {
145 match self {
146 Self::Run(_) => "query run",
147 Self::Sample(_) => "query sample",
148 Self::Explain(_) => "query explain",
149 Self::Analyze(_) => "query analyze",
150 Self::Plan(_) => "query plan",
151 Self::Lineage(_) => "query lineage",
152 Self::File(_) => "query file",
153 Self::Tx(_) => "query tx",
154 Self::Call(_) => "query call",
155 Self::Named(args) => args.action.published_name(),
161 }
162 }
163}
164
165impl data::DataCommand {
166 #[must_use]
168 pub const fn published_name(&self) -> &'static str {
169 match self {
170 Self::Export(_) => "data export",
171 Self::Import(_) => "data import",
172 }
173 }
174}
175
176impl server::ServerCommand {
177 #[must_use]
179 pub const fn published_name(&self) -> &'static str {
180 match self {
181 Self::Status(_) => "server status",
182 Self::Variables(_) => "server variables",
183 Self::Processes(_) => "server processes",
184 Self::Replica => "server replica",
185 Self::Kill(_) => "server kill",
186 Self::Capabilities => "server capabilities",
187 Self::Queries(_) => "server queries",
188 Self::Locks => "server locks",
189 }
190 }
191}
192
193impl history::HistoryCommand {
194 #[must_use]
196 pub const fn published_name(&self) -> &'static str {
197 match self {
198 Self::AsOf(_) => "history as-of",
199 Self::Between(_) => "history between",
200 Self::Tables(_) => "history tables",
201 }
202 }
203}
204
205impl config::ConfigCommand {
206 #[must_use]
208 pub const fn published_name(&self) -> &'static str {
209 match self {
210 Self::Set(_) => "config set",
211 Self::Get(_) => "config get",
212 Self::List(_) => "config list",
213 Self::Path => "config path",
214 Self::Unset(_) => "config unset",
215 Self::Doctor => "config doctor",
216 }
217 }
218}
219
220impl meta::MetaCommand {
221 #[must_use]
223 pub const fn published_name(&self) -> &'static str {
224 match self {
225 Self::Commands(_) => "meta commands",
226 Self::Schema(_) => "meta schema",
227 Self::Version => "meta version",
228 Self::Manual(_) => "meta manual",
229 Self::Completions(_) => "meta completions",
230 }
231 }
232}
233
234#[cfg(test)]
235mod tests {
236 use super::*;
237 use clap::CommandFactory;
238
239 #[test]
241 fn the_command_tree_is_well_formed() {
242 Cli::command().debug_assert();
243 }
244
245 #[test]
247 fn the_surface_has_the_published_command_count() {
248 fn leaves(command: &clap::Command) -> usize {
249 let mut total = 0;
250 for sub in command.get_subcommands() {
251 if sub.get_subcommands().next().is_some() {
252 total += leaves(sub);
253 } else {
254 total += 1;
255 }
256 }
257 total
258 }
259 const NAMED_EXTRA_LEAVES: usize = 3;
262 assert_eq!(leaves(&Cli::command()) - NAMED_EXTRA_LEAVES, 60);
263 }
264}