From 0194a42e1fd942170d97b7459fe0d5606bd352b9 Mon Sep 17 00:00:00 2001 From: WillRInternship Date: Thu, 7 Jul 2022 11:11:18 -0700 Subject: [PATCH 1/5] feat: changes name of delete command --- src/main.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7bd37fbf..6acc69e5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -110,7 +110,7 @@ enum CloudSignupCommand { #[derive(Debug, StructOpt)] enum CacheCommand { #[structopt(about = "Create a cache")] - Create { + CreateCache { #[structopt(long = "name", short = 'n')] cache_name: String, #[structopt(long, short, default_value = "default")] @@ -148,7 +148,7 @@ enum CacheCommand { }, #[structopt(about = "Delete the cache")] - Delete { + DeleteCache { #[structopt(long = "name", short = 'n')] cache_name: String, #[structopt(long, short, default_value = "default")] @@ -156,7 +156,7 @@ enum CacheCommand { }, #[structopt(about = "List all caches")] - List { + ListCache { #[structopt(long, short, default_value = "default")] profile: String, }, @@ -176,7 +176,7 @@ async fn entrypoint() -> Result<(), CliError> { match args.command { Subcommand::Cache { operation } => match operation { - CacheCommand::Create { + CacheCommand::CreateCache { cache_name, profile, } => { @@ -214,7 +214,7 @@ async fn entrypoint() -> Result<(), CliError> { ) .await?; } - CacheCommand::Delete { + CacheCommand::DeleteCache { cache_name, profile, } => { @@ -222,7 +222,7 @@ async fn entrypoint() -> Result<(), CliError> { commands::cache::cache_cli::delete_cache(cache_name.clone(), creds.token).await?; debug!("deleted cache {}", cache_name) } - CacheCommand::List { profile } => { + CacheCommand::ListCache { profile } => { let (creds, _config) = get_creds_and_config(&profile).await?; commands::cache::cache_cli::list_caches(creds.token).await? } From ab49efaab9484dcdd5b878fa8ef629335b2c62da Mon Sep 17 00:00:00 2001 From: WillRInternship Date: Thu, 7 Jul 2022 13:38:41 -0700 Subject: [PATCH 2/5] feat: adds new delete function to CLI --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/commands/cache/cache_cli.rs | 7 +++++++ src/main.rs | 28 ++++++++++++++++++++++++++-- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6eaae2e3..90f4a1f7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -818,9 +818,9 @@ dependencies = [ [[package]] name = "momento" -version = "0.5.4" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "874dd9d49adf223f60515bc3008c173fe408657ecb82473560d0877ae88554e1" +checksum = "f70111018ae229cf90aecc14c06717a8873b8ff1e73f7757f20fd6188b8e6ed1" dependencies = [ "chrono", "jsonwebtoken", diff --git a/Cargo.toml b/Cargo.toml index 2bbf7af0..8cf188c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ toml = "0.5.8" maplit = "1.0.2" configparser = "3.0.0" regex = "1" -momento = "0.5.4" +momento = "0.6.0" qrcode = "0.12.0" webbrowser = "0.7.1" diff --git a/src/commands/cache/cache_cli.rs b/src/commands/cache/cache_cli.rs index d971c7cc..80f0efa2 100644 --- a/src/commands/cache/cache_cli.rs +++ b/src/commands/cache/cache_cli.rs @@ -74,3 +74,10 @@ pub async fn get(cache_name: String, auth_token: String, key: String) -> Result< }; Ok(()) } + +pub async fn delete(cache_name: String, auth_token: String, key: String) -> Result<(), CliError> { + debug!("getting key: {} from cache: {}", key, cache_name); + + let mut client = get_momento_client(auth_token).await?; + interact_with_momento("getting...", client.delete(&cache_name, key)).await +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 6acc69e5..78dc7a49 100644 --- a/src/main.rs +++ b/src/main.rs @@ -155,8 +155,19 @@ enum CacheCommand { profile: String, }, + #[structopt(about = "Delete an item from the cache")] + Delete { + #[structopt(long = "name", short = 'n')] + cache_name: Option, + // TODO: Add support for non-string key-value + #[structopt(long, short)] + key: String, + #[structopt(long, short, default_value = "default")] + profile: String, + }, + #[structopt(about = "List all caches")] - ListCache { + ListCaches { #[structopt(long, short, default_value = "default")] profile: String, }, @@ -222,10 +233,23 @@ async fn entrypoint() -> Result<(), CliError> { commands::cache::cache_cli::delete_cache(cache_name.clone(), creds.token).await?; debug!("deleted cache {}", cache_name) } - CacheCommand::ListCache { profile } => { + CacheCommand::ListCaches { profile } => { let (creds, _config) = get_creds_and_config(&profile).await?; commands::cache::cache_cli::list_caches(creds.token).await? } + CacheCommand::Delete { + cache_name, + key, + profile, + } => { + let (creds, config) = get_creds_and_config(&profile).await?; + commands::cache::cache_cli::delete( + cache_name.unwrap_or(config.cache), + creds.token, + key, + ) + .await?; + } }, Subcommand::Configure { quick, profile } => { commands::configure::configure_cli::configure_momento(quick, &profile).await? From 1b37ae9d0aa3c0e10cfa6b79cefd08dac418f760 Mon Sep 17 00:00:00 2001 From: WillRInternship Date: Thu, 7 Jul 2022 15:08:22 -0700 Subject: [PATCH 3/5] chore: cleans lint --- src/commands/cache/cache_cli.rs | 2 +- src/main.rs | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/commands/cache/cache_cli.rs b/src/commands/cache/cache_cli.rs index 80f0efa2..765bd386 100644 --- a/src/commands/cache/cache_cli.rs +++ b/src/commands/cache/cache_cli.rs @@ -80,4 +80,4 @@ pub async fn delete(cache_name: String, auth_token: String, key: String) -> Resu let mut client = get_momento_client(auth_token).await?; interact_with_momento("getting...", client.delete(&cache_name, key)).await -} \ No newline at end of file +} diff --git a/src/main.rs b/src/main.rs index 78dc7a49..a937c8d7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -155,16 +155,16 @@ enum CacheCommand { profile: String, }, - #[structopt(about = "Delete an item from the cache")] - Delete { - #[structopt(long = "name", short = 'n')] - cache_name: Option, - // TODO: Add support for non-string key-value - #[structopt(long, short)] - key: String, - #[structopt(long, short, default_value = "default")] - profile: String, - }, + #[structopt(about = "Delete an item from the cache")] + Delete { + #[structopt(long = "name", short = 'n')] + cache_name: Option, + // TODO: Add support for non-string key-value + #[structopt(long, short)] + key: String, + #[structopt(long, short, default_value = "default")] + profile: String, + }, #[structopt(about = "List all caches")] ListCaches { @@ -247,7 +247,7 @@ async fn entrypoint() -> Result<(), CliError> { cache_name.unwrap_or(config.cache), creds.token, key, - ) + ) .await?; } }, From fa2bf39f969e27706acbdae27fcf0d9ac3ebad3d Mon Sep 17 00:00:00 2001 From: WillRInternship Date: Thu, 7 Jul 2022 15:24:26 -0700 Subject: [PATCH 4/5] chore: solves build failure --- tests/configure_profiles_test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/configure_profiles_test.rs b/tests/configure_profiles_test.rs index bad7b633..6f646fbd 100644 --- a/tests/configure_profiles_test.rs +++ b/tests/configure_profiles_test.rs @@ -29,7 +29,7 @@ mod tests { async fn momento_cache_delete_default_profile() { let test_cache_default = std::env::var("TEST_CACHE_DEFAULT").unwrap(); let mut cmd = Command::cargo_bin("momento").unwrap(); - cmd.args(&["cache", "delete", "--name", &test_cache_default]) + cmd.args(&["cache", "delete-cache", "--name", &test_cache_default]) .assert() .success(); } From 7fc802e5018d72a31d17caf98db831fd72031ac7 Mon Sep 17 00:00:00 2001 From: WillRInternship Date: Mon, 11 Jul 2022 09:51:37 -0700 Subject: [PATCH 5/5] chore: solves build failure --- tests/momento_additional_profile.rs | 6 +++--- tests/momento_default_profile.rs | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/momento_additional_profile.rs b/tests/momento_additional_profile.rs index eb48a85d..4e563317 100644 --- a/tests/momento_additional_profile.rs +++ b/tests/momento_additional_profile.rs @@ -9,7 +9,7 @@ mod tests { let mut cmd = Command::cargo_bin("momento").unwrap(); cmd.args(&[ "cache", - "create", + "create-cache", "--name", &test_cache_with_profile, "--profile", @@ -49,7 +49,7 @@ mod tests { test_cache_with_profile.push('\n'); let test_profile = std::env::var("TEST_PROFILE").unwrap(); let mut cmd = Command::cargo_bin("momento").unwrap(); - cmd.args(&["cache", "list", "--profile", &test_profile]) + cmd.args(&["cache", "list-caches", "--profile", &test_profile]) .assert() .stdout(test_cache_with_profile); } @@ -60,7 +60,7 @@ mod tests { let mut cmd = Command::cargo_bin("momento").unwrap(); cmd.args(&[ "cache", - "delete", + "delete-cache", "--name", &test_cache_with_profile, "--profile", diff --git a/tests/momento_default_profile.rs b/tests/momento_default_profile.rs index 657dd662..dfdd415b 100644 --- a/tests/momento_default_profile.rs +++ b/tests/momento_default_profile.rs @@ -8,7 +8,7 @@ mod tests { let test_cache_default = std::env::var("TEST_CACHE_DEFAULT").unwrap(); let output = Command::cargo_bin("momento") .unwrap() - .args(&["cache", "list"]) + .args(&["cache", "list-caches"]) .output() .unwrap() .stdout; @@ -19,13 +19,13 @@ mod tests { if !cache.is_empty() { Command::cargo_bin("momento") .unwrap() - .args(&["cache", "delete", "--name", cache]) + .args(&["cache", "delete-cache", "--name", cache]) .unwrap(); } } } let mut cmd = Command::cargo_bin("momento").unwrap(); - cmd.args(&["cache", "create", "--name", &test_cache_default]) + cmd.args(&["cache", "create-cache", "--name", &test_cache_default]) .assert() .success(); } @@ -48,7 +48,7 @@ mod tests { let mut test_cache_default = std::env::var("TEST_CACHE_DEFAULT").unwrap(); test_cache_default.push('\n'); let mut cmd = Command::cargo_bin("momento").unwrap(); - cmd.args(&["cache", "list"]) + cmd.args(&["cache", "list-caches"]) .assert() .stdout(test_cache_default); } @@ -56,7 +56,7 @@ mod tests { async fn momento_cache_delete_default_profile() { let test_cache_default = std::env::var("TEST_CACHE_DEFAULT").unwrap(); let mut cmd = Command::cargo_bin("momento").unwrap(); - cmd.args(&["cache", "delete", "--name", &test_cache_default]) + cmd.args(&["cache", "delete-cache", "--name", &test_cache_default]) .assert() .success(); }