summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormdecimus <mauro@stalw.art>2024-09-20 19:35:15 +0200
committermdecimus <mauro@stalw.art>2024-09-20 19:35:15 +0200
commit3001493462645cb95d4279e5349744f7592f1f10 (patch)
tree45d10199af6f9ae063dd97ac848566f7a6a69bdf
parentb59f5f1a10f97377047d81dda05d208a8d98c1c8 (diff)
Updated CLI deserialization format (closes #360 closes #553)
-rw-r--r--crates/cli/src/modules/database.rs34
1 files changed, 28 insertions, 6 deletions
diff --git a/crates/cli/src/modules/database.rs b/crates/cli/src/modules/database.rs
index 3ba06598..b9ec0846 100644
--- a/crates/cli/src/modules/database.rs
+++ b/crates/cli/src/modules/database.rs
@@ -14,6 +14,22 @@ use crate::modules::Response;
use super::cli::{Client, ServerCommands};
+#[derive(Debug, serde::Serialize, serde::Deserialize)]
+#[serde(tag = "type")]
+pub enum UpdateSettings {
+ Delete {
+ keys: Vec<String>,
+ },
+ Clear {
+ prefix: String,
+ },
+ Insert {
+ prefix: Option<String>,
+ values: Vec<(String, String)>,
+ assert_empty: bool,
+ },
+}
+
impl ServerCommands {
pub async fn exec(self, client: Client) {
match self {
@@ -40,17 +56,23 @@ impl ServerCommands {
.http_request::<Value, _>(
Method::POST,
"/api/settings",
- Some(vec![(key.clone(), value.unwrap_or_default())]),
+ Some(vec![UpdateSettings::Insert {
+ prefix: None,
+ values: vec![(key.clone(), value.unwrap_or_default())],
+ assert_empty: false,
+ }]),
)
.await;
eprintln!("Successfully added key {key}.");
}
ServerCommands::DeleteConfig { key } => {
client
- .http_request::<Value, String>(
- Method::DELETE,
- &format!("/api/settings/{key}"),
- None,
+ .http_request::<Value, _>(
+ Method::POST,
+ "/api/settings",
+ Some(vec![UpdateSettings::Delete {
+ keys: vec![key.clone()],
+ }]),
)
.await;
eprintln!("Successfully deleted key {key}.");
@@ -59,7 +81,7 @@ impl ServerCommands {
let results = client
.http_request::<Response<HashMap<String, String>>, String>(
Method::GET,
- &format!("/api/settings/list/{}", prefix.unwrap_or_default()),
+ &format!("/api/settings/list?prefix={}", prefix.unwrap_or_default()),
None,
)
.await