๐Ÿ“ฆ directus / cli

๐Ÿ“„ one.ts ยท 45 lines
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
45import { command } from '../../../../core/command';

export default command(
	{
		group: 'items',
		parameters: '<collection>',
		description: 'Delete one item in a collection',
		usage: `
			\`\`\`
			$ $0 items delete one <collection> --id <id>
			\`\`\`
		`,
		hints: ['del', 'rm', 'remove', 'exclude', 'destroy', 'explode'],
		documentation: `
			Deletes one item by it's primary key.
		`,
		features: {
			sdk: true,
		},
		options: function (builder) {
			return builder
				.option('id', {
					type: 'string',
					description: "The item's primary key id",
					demandOption: true,
				})
				.positional('collection', {
					type: 'string',
					description: "The collection's name",
					demandOption: true,
				});
		},
	},
	async function ({ output, sdk }, params) {
		await sdk.items(params.collection).deleteOne(params.id);
		await output.compose(async (ui) => {
			await ui.wrap((ui) => ui.text('Item successfully deleted'), 1);
		});

		return {
			deleted: true,
		};
	}
);