wapm_cli/commands/
config.rs1use crate::config::{get, set, Config};
2use structopt::StructOpt;
3
4#[derive(StructOpt, Debug)]
5pub enum ConfigOpt {
6 #[structopt(name = "set")]
7 Set(ConfigKeyValue),
9
10 #[structopt(name = "get")]
11 Get(ConfigKey),
13}
14
15#[derive(StructOpt, Debug)]
16pub struct ConfigKeyValue {
17 #[structopt(parse(from_str))]
18 key: String,
19
20 #[structopt(parse(from_str))]
21 value: String,
22}
23
24#[derive(StructOpt, Debug)]
25pub struct ConfigKey {
26 #[structopt(parse(from_str))]
27 key: String,
28}
29
30pub fn config(config_opt: ConfigOpt) -> anyhow::Result<()> {
31 let mut config = Config::from_file()?;
32 match config_opt {
33 ConfigOpt::Set(ConfigKeyValue { key, value }) => set(&mut config, key, value),
34 ConfigOpt::Get(ConfigKey { key }) => {
35 let value = get(&mut config, key)?;
36 println!("{}", value);
37 Ok(())
38 }
39 }
40}
41
42#[cfg(feature = "integration_tests")]
44impl ConfigOpt {
45 pub fn set(key: String, value: String) -> Self {
46 ConfigOpt::Set(ConfigKeyValue { key, value })
47 }
48
49 pub fn get(key: String) -> Self {
50 ConfigOpt::Get(ConfigKey { key })
51 }
52}