noosphere_cli/native/commands/sphere/
config.rs1use anyhow::Result;
2use noosphere_core::context::metadata::{COUNTERPART, GATEWAY_URL};
3use noosphere_core::data::Did;
4use noosphere_storage::KeyValueStore;
5
6use url::Url;
7
8use crate::native::{cli::ConfigGetCommand, cli::ConfigSetCommand, workspace::Workspace};
9
10pub async fn config_set(command: ConfigSetCommand, workspace: &Workspace) -> Result<()> {
12 workspace.ensure_sphere_initialized()?;
13 let context = workspace.sphere_context().await?;
14 let context = context.lock().await;
15
16 let mut db = context.db().clone();
17
18 match command {
19 ConfigSetCommand::GatewayUrl { url } => db.set_key(GATEWAY_URL, url).await?,
20 ConfigSetCommand::Counterpart { did } => db.set_key(COUNTERPART, did).await?,
21 };
22
23 Ok(())
24}
25
26pub async fn config_get(command: ConfigGetCommand, workspace: &Workspace) -> Result<()> {
28 workspace.ensure_sphere_initialized()?;
29 let context = workspace.sphere_context().await?;
30 let context = context.lock().await;
31
32 let db = context.db();
33
34 let value = match command {
35 ConfigGetCommand::GatewayUrl => db
36 .get_key::<_, Url>(GATEWAY_URL)
37 .await?
38 .map(|url| url.to_string()),
39 ConfigGetCommand::Counterpart => db
40 .get_key::<_, Did>(COUNTERPART)
41 .await?
42 .map(|did| did.to_string()),
43 };
44
45 if let Some(value) = value {
46 info!("{value}");
47 }
48
49 Ok(())
50}