-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathrm.ts
52 lines (41 loc) · 1.41 KB
/
rm.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { Args } from '@oclif/core';
import type { ApifyApiError } from 'apify-client';
import { ApifyCommand } from '../../lib/apify_command.js';
import { confirmAction } from '../../lib/commands/confirm.js';
import { error, info, success } from '../../lib/outputs.js';
import { getLoggedClientOrThrow } from '../../lib/utils.js';
export class ActorRmCommand extends ApifyCommand<typeof ActorRmCommand> {
static override description = 'Permanently removes an Actor from your account.';
static override args = {
actorId: Args.string({
description: 'The Actor ID to delete.',
required: true,
}),
};
async run() {
const { actorId } = this.args;
const apifyClient = await getLoggedClientOrThrow();
const actor = await apifyClient.actor(actorId).get();
if (!actor) {
error({ message: `Actor with ID "${actorId}" was not found on your account.` });
return;
}
const confirmedDelete = await confirmAction({
type: 'Actor',
failureMessage: `Your provided value does not match the Actor ID.`,
});
if (!confirmedDelete) {
info({
message: `Deletion of Actor "${actorId}" was canceled.`,
});
return;
}
try {
await apifyClient.actor(actorId).delete();
success({ message: `Actor with ID "${actorId}" was deleted.` });
} catch (err) {
const casted = err as ApifyApiError;
error({ message: `Failed to delete Actor "${actorId}".\n ${casted.message || casted}` });
}
}
}