Skip to main content

mariadb_cli/cli/
config.rs

1//! Stored configuration, written and read by this tool alone.
2//!
3//! Every key is written and read through a command here. No key is ever read
4//! from the process environment, because a value that changes with the
5//! surrounding shell is not a stored setting.
6
7use clap::{Args, Subcommand};
8
9/// The six configuration commands.
10#[derive(Debug, Clone, Subcommand)]
11pub enum ConfigCommand {
12    /// Write the value of a key.
13    Set(SetArgs),
14    /// Read the value of a key.
15    Get(KeyArgs),
16    /// List the effective value and the origin of every key.
17    List(ListArgs),
18    /// Show where the configuration lives.
19    Path,
20    /// Remove a stored key and fall back to its default.
21    Unset(KeyArgs),
22    /// Point out an invalid key, an unreadable file or a wrong permission.
23    Doctor,
24}
25
26/// Writing one key.
27///
28/// Both fields are optional to the argument layer and required to the command.
29/// Publishing the contract must cost nothing, and a caller asking what this
30/// command answers should not have to invent a key first. Absence is refused
31/// where the write actually happens, and carries a code.
32#[derive(Debug, Clone, Args)]
33pub struct SetArgs {
34    /// Key name.
35    pub key: Option<String>,
36    /// Value to store.
37    pub value: Option<String>,
38}
39
40/// Addressing one key.
41///
42/// Optional to the argument layer and required to the command, for the reason
43/// given on [`SetArgs`].
44#[derive(Debug, Clone, Args)]
45pub struct KeyArgs {
46    /// Key name.
47    pub key: Option<String>,
48}
49
50/// Listing the keys.
51#[derive(Debug, Clone, Args)]
52pub struct ListArgs {
53    /// List only keys that carry a stored value.
54    #[arg(long)]
55    pub stored_only: bool,
56}