-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdelete.ts
More file actions
53 lines (46 loc) · 1.62 KB
/
Copy pathdelete.ts
File metadata and controls
53 lines (46 loc) · 1.62 KB
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
53
import { Command } from '@cliffy/command';
import { handleCommandError } from '@/lib/errors.ts';
import { createAuthenticatedMuxClient } from '@/lib/mux.ts';
import { deletePlaybackId } from '@/lib/playback-ids.ts';
import { confirmPrompt } from '@/lib/prompt.ts';
interface DeleteOptions {
force?: boolean;
json?: boolean;
}
export const deleteCommand = new Command()
.description('Delete a playback ID from an asset')
.arguments('<asset-id:string> <playback-id:string>')
.option('-f, --force', 'Skip confirmation prompt')
.option('--json', 'Output JSON instead of pretty format')
.action(
async (options: DeleteOptions, assetId: string, playbackId: string) => {
try {
const mux = await createAuthenticatedMuxClient();
if (!options.force) {
if (options.json) {
throw new Error(
'Deletion requires --force flag when using --json output',
);
}
const confirmed = await confirmPrompt({
message: `Are you sure you want to delete playback ID ${playbackId}?`,
default: false,
});
if (!confirmed) {
console.log('Deletion cancelled.');
return;
}
}
await deletePlaybackId(mux, assetId, playbackId);
if (options.json) {
console.log(
JSON.stringify({ success: true, assetId, playbackId }, null, 2),
);
} else {
console.log(`Playback ID ${playbackId} deleted successfully`);
}
} catch (error) {
await handleCommandError(error, 'assets', 'delete', options);
}
},
);