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.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 new file mode 100644 index 00000000000..484ae240f39 --- /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 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_test cargo run identity remove --all --force