wash_cli/cmd/config/
mod.rs1use 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 #[clap(name = "put", alias = "create", about = "Put named configuration")]
18 PutCommand {
19 #[clap(flatten)]
20 opts: CliConnectionOpts,
21 #[clap(name = "name")]
23 name: String,
24 #[clap(name = "config_value", required = true)]
26 config_values: Vec<String>,
27 },
28 #[clap(name = "get")]
30 GetCommand {
31 #[clap(flatten)]
32 opts: CliConnectionOpts,
33 #[clap(name = "name")]
35 name: String,
36 },
37 #[clap(name = "del", alias = "delete")]
39 DelCommand {
40 #[clap(flatten)]
41 opts: CliConnectionOpts,
42 #[clap(name = "name")]
44 name: String,
45 },
46}
47
48pub 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}