diff --git a/src/cli/autocomplete/scripts/bash.sh b/src/cli/autocomplete/scripts/bash.sh index 5e7b960..4310f48 100644 --- a/src/cli/autocomplete/scripts/bash.sh +++ b/src/cli/autocomplete/scripts/bash.sh @@ -174,7 +174,7 @@ _{{FUNC_NAME}}_completions() { fi fi ;; - append|sign|broadcast|requirements|export|inspect) + append|sign|broadcast|requirements|export|inspect|delete) # These subcommands expect an invitation identifier as first arg. local pos=$((cword - subcmd_idx)) if [[ $pos -eq 1 ]]; then diff --git a/src/cli/commands/invitation.ts b/src/cli/commands/invitation.ts index 8c21461..70d0dc1 100644 --- a/src/cli/commands/invitation.ts +++ b/src/cli/commands/invitation.ts @@ -298,6 +298,7 @@ ${bold("Sub-commands:")} - requirements ${dim("Show requirements for an invitation")} - import ${dim("Import an invitation from a file")} - export [output-file] ${dim("Export an invitation to stdout or a file")} + - delete ${dim("Delete an invitation")} - inspect ${dim("Inspect an invitation")} - list ${dim("List all invitations")} @@ -955,6 +956,47 @@ export const handleInvitationCommand = async ( return handleInvitationExportCommand(deps, args.slice(1), options); } + case "delete": { + // Get the invitation identifier from the arguments + const invitationIdentifier = args[1]; + deps.io.verbose(`Invitation identifier: ${invitationIdentifier}`); + + // If they didnt provide us with an invitation identifier, print the help message and throw an error + // TODO: Should probably print a specific help message for this command? + if (!invitationIdentifier) { + deps.io.verbose("No invitation identifier provided"); + printInvitationHelp(deps.io); + throw new CommandError( + "invitation.delete.identifier_missing", + "No invitation identifier provided", + ); + } + + // Find the invitation instance in our list of invitations + const invitation = deps.app.invitations.find( + (candidate) => + candidate.data.invitationIdentifier === invitationIdentifier, + ); + + // If the invitation is not found, print an error and throw an error + if (!invitation) { + deps.io.err(`Invitation not found: ${invitationIdentifier}`); + throw new CommandError( + "invitation.delete.not_found", + `Invitation not found: ${invitationIdentifier}`, + ); + } + deps.io.verbose(`Invitation: ${formatObject(invitation.data)}`); + + // Delete the invitation + await invitation.delete(); + deps.io.verbose(`Invitation deleted: ${formatObject(invitation.data)}`); + deps.io.out(`Invitation deleted: ${invitationIdentifier}`); + + // Return the invitation identifier + return { invitationIdentifier }; + } + case "list": { // List all the invitations const invitations = await Promise.all(