mariadb_cli/cli/meta.rs
1//! Self-description: how a caller learns this tool without reading prose.
2
3use clap::{Args, Subcommand, ValueEnum};
4
5/// The five discovery commands.
6#[derive(Debug, Clone, Subcommand)]
7pub enum MetaCommand {
8 /// The command tree in structured form.
9 Commands(CommandsArgs),
10 /// The output contract of each command, with the type map.
11 Schema(SchemaArgs),
12 /// Identity of the product.
13 Version,
14 /// The product manual.
15 Manual(ManualArgs),
16 /// Shell completion support.
17 Completions(CompletionsArgs),
18}
19
20/// Listing the command tree.
21#[derive(Debug, Clone, Args)]
22pub struct CommandsArgs {
23 /// Include the global flags in the tree.
24 #[arg(long)]
25 pub with_globals: bool,
26}
27
28/// Emitting an output contract.
29#[derive(Debug, Clone, Args)]
30pub struct SchemaArgs {
31 /// Emit the contract of this command only.
32 #[arg(long, value_name = "COMMAND")]
33 pub command: Option<String>,
34 /// Emit the type map instead of a command contract.
35 #[arg(long, conflicts_with = "command")]
36 pub types: bool,
37}
38
39/// Emitting the manual.
40#[derive(Debug, Clone, Args)]
41pub struct ManualArgs {}
42
43/// Emitting completion support.
44#[derive(Debug, Clone, Args)]
45pub struct CompletionsArgs {
46 /// Which shell the support is for.
47 ///
48 /// Optional to the argument layer and required to the command. Publishing
49 /// the contract must cost nothing, and a caller asking what this command
50 /// answers should not have to pick a shell first. Absence is refused where
51 /// the script is actually generated, and carries a code.
52 #[arg(value_enum)]
53 pub shell: Option<Shell>,
54}
55
56/// The shells completion support is generated for.
57#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
58#[value(rename_all = "lower")]
59pub enum Shell {
60 /// The shell most Unix systems start with.
61 Bash,
62 /// The shell macOS starts with, and a common Linux choice.
63 Zsh,
64 /// A shell whose completion format is its own.
65 Fish,
66 /// A shell whose completion format is its own.
67 Elvish,
68 /// The shell Windows starts with.
69 PowerShell,
70}
71
72impl From<Shell> for clap_complete::Shell {
73 fn from(value: Shell) -> Self {
74 match value {
75 Shell::Bash => Self::Bash,
76 Shell::Zsh => Self::Zsh,
77 Shell::Fish => Self::Fish,
78 Shell::Elvish => Self::Elvish,
79 Shell::PowerShell => Self::PowerShell,
80 }
81 }
82}