Add invitation delete to cli
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -298,6 +298,7 @@ ${bold("Sub-commands:")}
|
||||
- requirements <invitation-id> ${dim("Show requirements for an invitation")}
|
||||
- import <invitation-file> ${dim("Import an invitation from a file")}
|
||||
- export <invitation-id> [output-file] ${dim("Export an invitation to stdout or a file")}
|
||||
- delete <invitation-id> ${dim("Delete an invitation")}
|
||||
- inspect <invitation-id | invitation-file> ${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(
|
||||
|
||||
Reference in New Issue
Block a user