wash_cli/cmd/config/
mod.rs

1//! `wash config` related (sub)commands
2
3use clap::Subcommand;
4use wash_lib::cli::{input_vec_to_hashmap, CliConnectionOpts, CommandOutput, OutputKind};
5
6use crate::cmd;
7use crate::secrets::ensure_not_secret;
8
9pub(crate) mod delete;
10pub(crate) mod get;
11pub(crate) mod put;
12
13#[derive(Debug, Clone, Subcommand)]
14#[allow(clippy::enum_variant_names)]
15pub enum ConfigCliCommand {
16    /// Put a named configuration
17    #[clap(name = "put", alias = "create", about = "Put named configuration")]
18    PutCommand {
19        #[clap(flatten)]
20        opts: CliConnectionOpts,
21        /// The name of the configuration to put
22        #[clap(name = "name")]
23        name: String,
24        /// The configuration values to put, in the form of `key=value`. Can be specified multiple times, but must be specified at least once.
25        #[clap(name = "config_value", required = true)]
26        config_values: Vec<String>,
27    },
28    /// Get a named configuration
29    #[clap(name = "get")]
30    GetCommand {
31        #[clap(flatten)]
32        opts: CliConnectionOpts,
33        /// The name of the configuration to get
34        #[clap(name = "name")]
35        name: String,
36    },
37    /// Delete a named configuration
38    #[clap(name = "del", alias = "delete")]
39    DelCommand {
40        #[clap(flatten)]
41        opts: CliConnectionOpts,
42        /// The name of the configuration to delete
43        #[clap(name = "name")]
44        name: String,
45    },
46}
47
48/// Handle any `wash config` prefixed (sub)command
49pub async fn handle_command(
50    command: ConfigCliCommand,
51    output_kind: OutputKind,
52) -> anyhow::Result<CommandOutput> {
53    match command {
54        ConfigCliCommand::PutCommand {
55            opts,
56            name,
57            config_values,
58        } => {
59            ensure_not_secret(&name)?;
60            cmd::config::put::invoke(
61                opts,
62                &name,
63                input_vec_to_hashmap(config_values)?,
64                output_kind,
65            )
66            .await
67        }
68        ConfigCliCommand::GetCommand { opts, name } => {
69            ensure_not_secret(&name)?;
70            cmd::config::get::invoke(opts, &name, output_kind).await
71        }
72        ConfigCliCommand::DelCommand { opts, name } => {
73            ensure_not_secret(&name)?;
74            cmd::config::delete::invoke(opts, &name, output_kind).await
75        }
76    }
77}