Skip to content

Commit

Permalink
Fix Spacetime Identity Remove (#33)
Browse files Browse the repository at this point in the history
* Fix bug and added a test

* Test updates

* Fix tests

---------

Co-authored-by: Boppy <no-reply@boppygames.gg>
  • Loading branch information
2 people authored and cloutiertyler committed Aug 1, 2023
1 parent 72d1007 commit 0d0b97c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
11 changes: 10 additions & 1 deletion crates/cli/src/subcommands/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ fn get_subcommands() -> Vec<Command> {
.arg(
Arg::new("all")
.long("all")
.short('a')
.help("Remove all identities from your spacetime config")
.action(ArgAction::SetTrue)
.conflicts_with("identity")
Expand All @@ -102,7 +103,6 @@ fn get_subcommands() -> Vec<Command> {
.long("force")
.help("Removes all identities without prompting (for CI usage)")
.action(ArgAction::SetTrue)
.requires("all")
.conflicts_with("identity")
.required_unless_present("identity"),
),
Expand Down Expand Up @@ -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::<String>("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) {
Expand Down
File renamed without changes.
23 changes: 23 additions & 0 deletions test/tests/identity-remove-2.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0d0b97c

Please sign in to comment.