-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.rs
68 lines (62 loc) · 2.14 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
mod cli;
mod store;
mod utils;
use cli::*;
use anyhow::{Context, Result};
#[tokio::main]
async fn main() -> Result<()> {
let cli = Cli::parse();
let mut safir = store::init_safir().await.context("loading safir store")?;
match cli.command {
Commands::Add { key, value } => safir.add(key.to_owned(), value.to_owned()).await?,
Commands::Get { keys } => {
let kvs = safir.get(keys.to_owned()).await?;
utils::display_multiple_kv(kvs);
}
Commands::Rm { keys } => safir.remove(keys.to_owned()).await?,
Commands::Alias { keys } => {
let kvs = safir.get(keys.to_owned()).await?;
utils::custom_display("alias", kvs);
}
Commands::Export { keys } => {
let kvs = safir.get(keys.to_owned()).await?;
utils::custom_display("export", kvs);
}
Commands::List => {
let kvs = safir.list().await?;
utils::display_multiple_kv(kvs);
}
Commands::Clear => safir.clear().await?,
Commands::Purge => safir.purge().await?,
Commands::Mode { mode } => {
let mut cfg = safir.get_config();
cfg.mode = mode;
cfg.write().context("writing config out")?;
println!(
"Set store mode to: '{:?}'\nActive on the next run of Safir!",
cfg.mode
);
}
Commands::Use { environment } => {
let mut cfg = safir.get_config();
cfg.environment = environment.clone();
cfg.write().context("writing config out")?;
println!("Using environment '{}'", environment);
}
Commands::Env => {
let cfg = safir.get_config();
let current_env = cfg.environment;
let envs = safir.environments().await?;
println!("Safir environments:");
for env in envs {
let penv = if env == current_env {
format!("{env} <- Currently loaded")
} else {
env
};
println!("- {penv}");
}
}
}
Ok(())
}