-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathsake.ts
163 lines (162 loc) · 4.25 KB
/
sake.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
const commonOptions: Fig.Option[] = [
{
name: ["--config-path", "-c"],
description: "Specify the path to the configuration file",
args: {
name: "path",
template: "filepaths",
},
isPersistent: true,
},
{
name: ["--sake-app-path", "-s"],
description: "Specify the path for the SakeApp package",
args: {
name: "path",
template: "folders",
},
isPersistent: true,
},
];
const commonCommandSpecificOptions: Fig.Option[] = [
{
name: "--case-converting-strategy",
description: "Specify the strategy for converting command names' case",
args: {
name: "strategy",
default: "keepOriginal",
suggestions: ["keepOriginal", "toSnakeCase", "toKebabCase"],
},
priority: 55,
},
{
name: ["--sake-app-prebuilt-binary-path", "-b"],
description: "Specify the path to the prebuilt SakeApp binary",
args: {
name: "path",
template: "filepaths",
},
priority: 55,
},
];
const completionSpec: Fig.Spec = {
name: "sake",
description:
"🍶 Swift-based utility for managing project commands, inspired by Make",
generateSpec: async (_tokens, executeShellCommand) => {
const { stdout } = await executeShellCommand({
command: "sake",
args: ["list", "--json"],
});
const commands = JSON.parse(stdout);
const subcommands = Object.keys(commands.groups).reduce(
(acc, groupName) => {
const group = commands.groups[groupName];
return [
...acc,
...group.map((command: { name: string; description: string }) => {
return {
name: command.name,
description: command.description || "The command to run",
priority: 76,
icon: "🍶",
options: [...commonOptions, ...commonCommandSpecificOptions],
};
}),
];
},
[]
);
return {
name: "sake",
subcommands,
};
},
subcommands: [
{
name: "init",
description:
"Initialize a new SakeApp project template for defining commands",
options: [...commonOptions],
},
{
name: "clean",
description:
"Remove all build artifacts generated by the SakeApp to ensure a clean state for future builds",
options: [...commonOptions],
},
{
name: "edit",
description: "Open the SakeApp in Xcode (macOS only)",
options: [...commonOptions],
},
{
name: "list",
description: "List all available commands defined in the SakeApp",
options: [
...commonOptions,
...commonCommandSpecificOptions,
{
name: ["--json", "-j"],
description: "Output the list of commands in JSON format",
priority: 45,
},
],
},
{
name: "build",
description: "Manually trigger a rebuild of the SakeApp",
options: [
...commonOptions,
{
name: "--show-bin-path",
description: "Print the path to the built SakeApp executable",
priority: 45,
},
],
},
{
name: "run",
description: "Run the specified command from the SakeApp",
args: {
name: "command",
description: "The command to run",
generators: {
script: ["sake", "list", "--json"],
postProcess: (output) => {
const commands = JSON.parse(output);
return Object.keys(commands.groups).reduce((acc, groupName) => {
const group = commands.groups[groupName];
return [
...acc,
...group.map((command) => {
return {
name: command.name,
description: command.description,
priority: 76,
icon: "🍶",
};
}),
];
}, []);
},
},
},
options: [...commonOptions, ...commonCommandSpecificOptions],
},
],
options: [
{
name: ["--help", "-h"],
description: "Show help information",
isPersistent: true,
priority: 40,
},
{
name: "--version",
description: "Show the version",
priority: 40,
},
],
};
export default completionSpec;