mariadb-cli 0.1.1

One-shot agent-native command line client for MariaDB servers
Documentation
//! Self-description: how a caller learns this tool without reading prose.

use clap::{Args, Subcommand, ValueEnum};

/// The five discovery commands.
#[derive(Debug, Clone, Subcommand)]
pub enum MetaCommand {
    /// The command tree in structured form.
    Commands(CommandsArgs),
    /// The output contract of each command, with the type map.
    Schema(SchemaArgs),
    /// Identity of the product.
    Version,
    /// The product manual.
    Manual(ManualArgs),
    /// Shell completion support.
    Completions(CompletionsArgs),
}

/// Listing the command tree.
#[derive(Debug, Clone, Args)]
pub struct CommandsArgs {
    /// Include the global flags in the tree.
    #[arg(long)]
    pub with_globals: bool,
}

/// Emitting an output contract.
#[derive(Debug, Clone, Args)]
pub struct SchemaArgs {
    /// Emit the contract of this command only.
    #[arg(long, value_name = "COMMAND")]
    pub command: Option<String>,
    /// Emit the type map instead of a command contract.
    #[arg(long, conflicts_with = "command")]
    pub types: bool,
}

/// Emitting the manual.
#[derive(Debug, Clone, Args)]
pub struct ManualArgs {}

/// Emitting completion support.
#[derive(Debug, Clone, Args)]
pub struct CompletionsArgs {
    /// Which shell the support is for.
    ///
    /// Optional to the argument layer and required to the command. Publishing
    /// the contract must cost nothing, and a caller asking what this command
    /// answers should not have to pick a shell first. Absence is refused where
    /// the script is actually generated, and carries a code.
    #[arg(value_enum)]
    pub shell: Option<Shell>,
}

/// The shells completion support is generated for.
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
#[value(rename_all = "lower")]
pub enum Shell {
    /// The shell most Unix systems start with.
    Bash,
    /// The shell macOS starts with, and a common Linux choice.
    Zsh,
    /// A shell whose completion format is its own.
    Fish,
    /// A shell whose completion format is its own.
    Elvish,
    /// The shell Windows starts with.
    PowerShell,
}

impl From<Shell> for clap_complete::Shell {
    fn from(value: Shell) -> Self {
        match value {
            Shell::Bash => Self::Bash,
            Shell::Zsh => Self::Zsh,
            Shell::Fish => Self::Fish,
            Shell::Elvish => Self::Elvish,
            Shell::PowerShell => Self::PowerShell,
        }
    }
}