forked from withfig/autocomplete
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplease.ts
More file actions
71 lines (62 loc) · 1.64 KB
/
please.ts
File metadata and controls
71 lines (62 loc) · 1.64 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
interface Argument {
name: string;
is_required: boolean;
is_array: boolean;
description: string;
default: string;
}
interface Option {
name: string;
shortcut: string;
accept_value: boolean;
is_value_required: boolean;
is_multiple: false;
description: string;
default: string;
}
const completionSpec: Fig.Spec = {
name: "please",
description: "Statamic Please command",
generateSpec: async (tokens, executeShellCommand) => {
const out = await executeShellCommand("php please list --format=json");
const subcommands = [];
try {
const commandDefinition = JSON.parse(out);
commandDefinition.commands.map((command) => {
subcommands.push({
name: command.name,
description: command.description,
args: Object.values(command.definition.arguments).map(
(argument: Argument) => {
return {
name: argument.name,
description: argument.description,
isOptional: !argument.is_required,
};
}
),
options: Object.values(command.definition.options).map(
(option: Option) => {
const names = [option.name];
if (option.shortcut !== "") {
names.push(option.shortcut);
}
return {
name: names,
description: option.description,
};
}
),
});
});
} catch (err) {
console.error(err);
}
return {
name: "please",
debounce: true,
subcommands,
};
},
};
export default completionSpec;