From 45ad45f0b7ea292155c3eec8dddcd2bf1d901442 Mon Sep 17 00:00:00 2001 From: mdecimus Date: Sun, 27 Oct 2024 20:07:35 +0100 Subject: [PATCH] Fix deleting single keys --- crates/common/src/manager/console.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/crates/common/src/manager/console.rs b/crates/common/src/manager/console.rs index f3c835f80..67ffc46db 100644 --- a/crates/common/src/manager/console.rs +++ b/crates/common/src/manager/console.rs @@ -98,12 +98,11 @@ pub async fn store_console(store: Store) { .expect("Failed to scan keys"); } } - "delete" => { - if ![2, 3].contains(&parts.len()) { - println!("Usage: delete []"); - } else if let Some(key) = parse_key(parts[1]) { - if let Some(to_key) = parse_key(parts[2]) { - let mut from_key = key.into_iter(); + "delete" => match (parts.get(1), parts.get(2)) { + (Some(from_key), Some(to_key)) => { + if let (Some(from_key), Some(to_key)) = (parse_key(from_key), parse_key(to_key)) + { + let mut from_key = from_key.into_iter(); let mut to_key = to_key.into_iter(); let from_key = AnyKey { @@ -150,7 +149,10 @@ pub async fn store_console(store: Store) { } else { println!("No keys found."); } - } else { + } + } + (Some(key), None) => { + if let Some(key) = parse_key(key) { println!("Deleting key: {:?}", key); let mut key = key.into_iter(); let mut batch = BatchBuilder::new(); @@ -163,7 +165,10 @@ pub async fn store_console(store: Store) { } } } - } + _ => { + println!("Usage: delete []"); + } + }, "get" => { if parts.len() != 2 { println!("Usage: get ");