From 918bc8f7970a497ee94325b6fd7ba94bed8bbef5 Mon Sep 17 00:00:00 2001 From: Boppy Date: Wed, 28 Jun 2023 14:02:30 -0500 Subject: [PATCH 1/3] Fix bug and added a test --- crates/cli/src/subcommands/identity.rs | 11 ++++++++++- test/tests/identity-remove-2.sh | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 test/tests/identity-remove-2.sh diff --git a/crates/cli/src/subcommands/identity.rs b/crates/cli/src/subcommands/identity.rs index d8ea0c89cd6..bf9fce3037a 100644 --- a/crates/cli/src/subcommands/identity.rs +++ b/crates/cli/src/subcommands/identity.rs @@ -93,6 +93,7 @@ fn get_subcommands() -> Vec { .arg( Arg::new("all") .long("all") + .short('a') .help("Remove all identities from your spacetime config") .action(ArgAction::SetTrue) .conflicts_with("identity") @@ -102,7 +103,6 @@ fn get_subcommands() -> Vec { .long("force") .help("Removes all identities without prompting (for CI usage)") .action(ArgAction::SetTrue) - .requires("all") .conflicts_with("identity") .required_unless_present("identity"), ), @@ -220,6 +220,15 @@ async fn exec_init_default(mut config: Config, args: &ArgMatches) -> Result<(), async fn exec_remove(mut config: Config, args: &ArgMatches) -> Result<(), anyhow::Error> { let identity_or_name = args.get_one::("identity"); let force = args.get_flag("force"); + let all = args.get_flag("all"); + + if !all && identity_or_name.is_none() { + return Err(anyhow::anyhow!("Must provide an identity or name to remove")); + } + + if force && !all { + return Err(anyhow::anyhow!("The --force flag can only be used with --all")); + } if let Some(identity_or_name) = identity_or_name { let ic = if is_hex_identity(identity_or_name) { diff --git a/test/tests/identity-remove-2.sh b/test/tests/identity-remove-2.sh new file mode 100644 index 00000000000..d7397d3a0e7 --- /dev/null +++ b/test/tests/identity-remove-2.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +if [ "$DESCRIBE_TEST" = 1 ] ; then + echo "This test checks to see if you're able to delete an identity from your local ~/.spacetime/config.toml file." + exit +fi + +set -euox pipefail +set -x + +source "./test/lib.include" + +run_test cargo run identity new --no-email +run_test cargo run identity new --no-email +IDENT=$(grep IDENTITY "$TEST_OUT" | awk '{print $2}') +run_test cargo run identity list +[ "1" == "$(grep -c "$IDENT" "$TEST_OUT")" ] + +run_test cargo run identity remove "$IDENT" +run_test cargo run identity list +[ "0" == "$(grep -c "$IDENT" "$TEST_OUT")" ] + +echo "y" | run_fail_test cargo run identity remove --all From ffa6734deabdf0ede6cc5e25529e0f009222c790 Mon Sep 17 00:00:00 2001 From: Boppy Date: Wed, 28 Jun 2023 14:04:54 -0500 Subject: [PATCH 2/3] Test updates --- ...dentity-remove.sh => identity-remove-1.sh} | 0 test/tests/identity-remove-2.sh | 2 +- test/tests/identity-remove-3.sh | 23 +++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) rename test/tests/{identity-remove.sh => identity-remove-1.sh} (100%) create mode 100644 test/tests/identity-remove-3.sh diff --git a/test/tests/identity-remove.sh b/test/tests/identity-remove-1.sh similarity index 100% rename from test/tests/identity-remove.sh rename to test/tests/identity-remove-1.sh diff --git a/test/tests/identity-remove-2.sh b/test/tests/identity-remove-2.sh index d7397d3a0e7..9fd881e6178 100644 --- a/test/tests/identity-remove-2.sh +++ b/test/tests/identity-remove-2.sh @@ -1,7 +1,7 @@ #!/bin/bash if [ "$DESCRIBE_TEST" = 1 ] ; then - echo "This test checks to see if you're able to delete an identity from your local ~/.spacetime/config.toml file." + echo "This test checks to see if you're able to delete an identity without --force" exit fi diff --git a/test/tests/identity-remove-3.sh b/test/tests/identity-remove-3.sh new file mode 100644 index 00000000000..ef50ddc51ea --- /dev/null +++ b/test/tests/identity-remove-3.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +if [ "$DESCRIBE_TEST" = 1 ] ; then + echo "This test checks to see if you're able to delete all identities with --force" + exit +fi + +set -euox pipefail +set -x + +source "./test/lib.include" + +run_test cargo run identity new --no-email +run_test cargo run identity new --no-email +IDENT=$(grep IDENTITY "$TEST_OUT" | awk '{print $2}') +run_test cargo run identity list +[ "1" == "$(grep -c "$IDENT" "$TEST_OUT")" ] + +run_test cargo run identity remove "$IDENT" +run_test cargo run identity list +[ "0" == "$(grep -c "$IDENT" "$TEST_OUT")" ] + +run_fail_test cargo run identity remove --all --force From 45c2caf388e903a5b0126b7e1e198d9a03e0207a Mon Sep 17 00:00:00 2001 From: Boppy Date: Thu, 29 Jun 2023 01:43:37 -0500 Subject: [PATCH 3/3] Fix tests --- test/tests/identity-remove-2.sh | 4 ++-- test/tests/identity-remove-3.sh | 23 ----------------------- 2 files changed, 2 insertions(+), 25 deletions(-) delete mode 100644 test/tests/identity-remove-3.sh diff --git a/test/tests/identity-remove-2.sh b/test/tests/identity-remove-2.sh index 9fd881e6178..484ae240f39 100644 --- a/test/tests/identity-remove-2.sh +++ b/test/tests/identity-remove-2.sh @@ -1,7 +1,7 @@ #!/bin/bash if [ "$DESCRIBE_TEST" = 1 ] ; then - echo "This test checks to see if you're able to delete an identity without --force" + echo "This test checks to see if you're able to delete all identities with --force" exit fi @@ -20,4 +20,4 @@ run_test cargo run identity remove "$IDENT" run_test cargo run identity list [ "0" == "$(grep -c "$IDENT" "$TEST_OUT")" ] -echo "y" | run_fail_test cargo run identity remove --all +run_test cargo run identity remove --all --force diff --git a/test/tests/identity-remove-3.sh b/test/tests/identity-remove-3.sh deleted file mode 100644 index ef50ddc51ea..00000000000 --- a/test/tests/identity-remove-3.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -if [ "$DESCRIBE_TEST" = 1 ] ; then - echo "This test checks to see if you're able to delete all identities with --force" - exit -fi - -set -euox pipefail -set -x - -source "./test/lib.include" - -run_test cargo run identity new --no-email -run_test cargo run identity new --no-email -IDENT=$(grep IDENTITY "$TEST_OUT" | awk '{print $2}') -run_test cargo run identity list -[ "1" == "$(grep -c "$IDENT" "$TEST_OUT")" ] - -run_test cargo run identity remove "$IDENT" -run_test cargo run identity list -[ "0" == "$(grep -c "$IDENT" "$TEST_OUT")" ] - -run_fail_test cargo run identity remove --all --force