-
Notifications
You must be signed in to change notification settings - Fork 1
/
questions.js
340 lines (340 loc) · 10.3 KB
/
questions.js
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
export {};
// import fs from "fs";
// import { key } from "./newCommands/apikey";
// import { checkout } from "./commands/clone";
// import { deploy, redeploy } from "./newCommands/deploy";
// import { envvar } from "./newCommands/envvar";
// import { event } from "./newCommands/event";
// import { fetch } from "./newCommands/fetch";
// import { group } from "./commands/group";
// import { BITBUCKET_FILE, hosting } from "./commands/hosting";
// import { org } from "./commands/org";
// import { queue } from "./commands/queue";
// import { quickstart } from "./commands/quickstart";
// import { register } from "./newCommands/register";
// import { repo } from "./newCommands/repo";
// import { role } from "./newCommands/role";
// import {
// SPECIAL_FOLDERS,
// do_delete_group,
// do_delete_org,
// do_help,
// do_join,
// do_spending,
// } from "./executors";
// import { Option, choice, shortText } from "./prompt";
// import {
// Path,
// abort,
// addExitMessage,
// addToExecuteQueue,
// directoryNames,
// fetchOrgRaw,
// finish,
// getCache,
// sshReq,
// } from "./utils";
//
// function help() {
// addToExecuteQueue(() => do_help());
// return finish();
// }
//
// function spending(org: string) {
// addToExecuteQueue(() => do_spending(org));
// return finish();
// }
//
// function delete_group_name(org: string, group: string) {
// addToExecuteQueue(() => do_delete_group(org, group));
// return finish();
// }
//
// function delete_org_name(org: string) {
// addToExecuteQueue(() => do_delete_org(org));
// return finish();
// }
//
// async function extra(orgName: string, pathToRoot: string) {
// try {
// const options: Option[] = [];
// options.push({
// long: "role",
// short: "o",
// text: "add or assign roles to users in the organization",
// action: () => role(orgName),
// });
// options.push({
// long: "usage",
// short: "u",
// text: "view usage breakdown for the last two months",
// action: () => spending(orgName),
// });
// options.push({
// long: "register",
// short: "e",
// text: "register an additional sshkey or email to account",
// action: () => register(),
// });
// if (!fs.existsSync(pathToRoot + BITBUCKET_FILE)) {
// options.push({
// long: "hosting",
// text: "configure git hosting with bitbucket", // TODO add github, gitlab, and azure devops
// action: () => hosting(pathToRoot, orgName),
// });
// }
// options.push({
// long: "help",
// short: "h",
// text: "help diagnose potential issues",
// action: () => help(),
// });
// return await choice("What would you like to do?", options).then();
// } catch (e) {
// throw e;
// }
// }
//
// async function delete_group(org: string) {
// try {
// const resp = await sshReq(`list-teams`, `--org`, org);
// const orgs: string[] = JSON.parse(resp);
// return await choice(
// "Which service GROUP do you want to delete?",
// orgs.map((x) => ({
// long: x,
// text: `delete ${x}`,
// action: () => delete_group_name(org, x),
// })),
// { disableAutoPick: true }
// ).then();
// } catch (e) {
// throw e;
// }
// }
//
// async function delete_org() {
// try {
// const resp = await sshReq(`list-organizations`);
// const orgs: string[] = JSON.parse(resp);
// return await choice(
// "Which ORGANIZATION do you want to delete?",
// orgs.map((x) => ({
// long: x,
// text: `delete ${x}`,
// action: () => delete_org_name(x),
// })),
// { disableAutoPick: true }
// ).then();
// } catch (e) {
// throw e;
// }
// }
//
// function please_register_first() {
// addExitMessage(`Please run '${process.env["COMMAND"]} register' first.`);
// return abort();
// }
//
// export async function start() {
// try {
// const rawStruct = fetchOrgRaw();
// if (rawStruct.org !== null) {
// const orgName = rawStruct.org.name;
// // If in org
// const options: Option[] = [];
// const selectedGroup: { name: string; path: Path } | null = null;
// const struct = {
// org: rawStruct.org,
// serviceGroup:
// rawStruct.serviceGroup !== null &&
// !SPECIAL_FOLDERS.includes(rawStruct.serviceGroup)
// ? rawStruct.serviceGroup
// : null,
// inEventCatalogue: rawStruct.serviceGroup === "event-catalogue",
// inPublic: rawStruct.serviceGroup === "public",
// pathToRoot: rawStruct.pathToRoot,
// };
// if (struct.serviceGroup !== null) {
// selectedGroup = {
// name: struct.serviceGroup,
// path: new Path(struct.pathToRoot).withoutLastUp(),
// };
// } else {
// const serviceGroups = directoryNames(new Path(), [
// "event-catalogue",
// "public",
// ]);
// if (serviceGroups.length === 1) {
// selectedGroup = {
// name: serviceGroups[0].name,
// path: new Path(serviceGroups[0].name),
// };
// }
// }
//
// options.push({
// long: "rapids",
// short: "q",
// text: "view or post messages to the rapids",
// action: () => queue(orgName, 0),
// });
// if (
// fs.existsSync("merrymake.json") ||
// struct.inEventCatalogue ||
// struct.inPublic
// ) {
// // Inside a service
// options.push({
// long: "deploy",
// short: "d",
// text: "deploy service to the cloud",
// action: () => deploy(),
// });
// options.push({
// long: "redeploy",
// short: "r",
// text: "redeploy service to the cloud",
// action: () => redeploy(),
// });
// } else {
// // Not inside a service
// options.push({
// long: "fetch",
// short: "f",
// text: "fetch updates to service groups and repos",
// action: () => fetch(),
// });
// if (selectedGroup !== null) {
// // Inside a service group or has one service
// const selectedGroup_hack = selectedGroup;
// options.push({
// long: "repo",
// short: "r",
// text: "add or edit repository",
// action: () =>
// repo(selectedGroup_hack.path, orgName, selectedGroup_hack.name),
// });
// }
// }
// // if (fs.existsSync("merrymake.json")) {
// // options.push({
// // long: "build",
// // short: "b",
// // text: "build service locally",
// // action: () => build(),
// // });
// // }
//
// if (selectedGroup !== null) {
// // Inside a service group or service
// const selectedGroup_hack = selectedGroup;
// options.push({
// long: "envvar",
// short: "e",
// text: "add or edit envvar for service group",
// action: () => envvar(orgName, selectedGroup_hack.name),
// });
// }
//
// if (struct.serviceGroup === null) {
// // In top level of organization
// options.push({
// long: "group",
// short: "g",
// text: "create a service group",
// action: () => group(new Path(), orgName),
// });
// options.push({
// long: "delete",
// short: "d",
// text: "delete a service group",
// action: () => delete_group(orgName),
// });
// }
//
// // options.push({
// // long: "cron",
// // short: "c",
// // text: "add or edit cron jobs for the organization",
// // action: () => cron(orgName),
// // });
// options.push({
// long: "key",
// short: "k",
// text: "add or edit api-keys for the organization",
// action: () => key(orgName),
// });
// options.push({
// long: "event",
// short: "v",
// text: "allow or disallow events through api-keys for the organization",
// action: () => event(orgName),
// });
// options.push({
// long: "other",
// short: "o",
// text: "other actions",
// action: () => extra(orgName, struct.pathToRoot),
// });
//
// return await choice("What would you like to do?", options).then();
// } else {
// const cache = getCache();
// const options: (Option & { weight: number })[] = [];
// options.push({
// long: "register",
// short: "r",
// text: "register new device or email",
// action: () => register(),
// weight: !cache.registered ? 10 : 1,
// });
// options.push({
// long: "quickstart",
// text: "quickstart with auto registration and a standard demo organization",
// action: () => quickstart(),
// weight: !cache.registered ? 15 : 2,
// });
// options.push({
// long: "org",
// short: "o",
// text: "create a new organization",
// action: () => (cache.registered ? org() : please_register_first()),
// weight: 5,
// });
// options.push({
// long: "clone",
// short: "c",
// text: "clone an existing organization",
// action: () => (cache.registered ? checkout() : please_register_first()),
// weight: cache.hasOrgs ? 10 : 3,
// });
// options.push({
// long: "delete",
// short: "d",
// text: "delete an organization",
// action: () =>
// cache.registered ? delete_org() : please_register_first(),
// weight: cache.hasOrgs ? 10 : 3,
// });
// options.push({
// long: "join",
// short: "j",
// text: "request to join an existing organization",
// action: () => (cache.registered ? join() : please_register_first()),
// weight: 4,
// });
// options.push({
// long: "help",
// text: "help diagnose potential issues",
// action: () => help(),
// weight: 0,
// });
// options.sort((a, b) => b.weight - a.weight);
// return await choice("What would you like to do?", options).then();
// }
// } catch (e) {
// throw e;
// }
// }
//