Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
Allow use of same json file to bulk delete as bulk put
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleymichal committed Sep 12, 2019
1 parent 109b3a5 commit 7de1050
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/commands/kv/bulk/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::fs::metadata;
use std::path::Path;

use cloudflare::endpoints::workerskv::delete_bulk::DeleteBulk;
use cloudflare::endpoints::workerskv::write_bulk::KeyValuePair;
use cloudflare::framework::apiclient::ApiClient;

use crate::commands::kv;
Expand All @@ -31,12 +32,12 @@ pub fn delete(
Err(e) => failure::bail!(e),
}

let keys: Result<Vec<String>, failure::Error> = match &metadata(filename) {
let pairs: Result<Vec<KeyValuePair>, failure::Error> = match &metadata(filename) {
Ok(file_type) if file_type.is_file() => {
let data = fs::read_to_string(filename)?;
let keys_vec = serde_json::from_str(&data);
if keys_vec.is_err() {
failure::bail!("Failed to decode JSON. Please make sure to follow the format, [\"test_key_1\", \"test_key_2\", ...]")
failure::bail!("Failed to decode JSON. Please make sure to follow the format, [{\"key\": \"test_key\", \"value\": \"test_value\"}, ...]")
} else {
Ok(keys_vec.unwrap())
}
Expand All @@ -45,7 +46,9 @@ pub fn delete(
Err(e) => failure::bail!("{}", e),
};

delete_bulk(target, user, namespace_id, keys?)
let keys: Vec<String> = pairs?.iter().map(|kv| kv.key.to_owned()).collect();

delete_bulk(target, user, namespace_id, keys)
}

fn delete_bulk(
Expand Down
2 changes: 1 addition & 1 deletion src/commands/kv/namespace/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn create(
};
println!(
"kv-namespaces = [ \n\
\t {{ binding: \"{}\", id: \"{}\" }} \n\
\t {{ binding = \"{}\", id = \"{}\" }} \n\
]",
binding, success.result.id
);
Expand Down

0 comments on commit 7de1050

Please sign in to comment.