1
- const { localConfig } = require('./config');
1
+ const chalk = require("chalk");
2
+ const { localConfig, globalConfig } = require('./config');
2
3
const { projectsList } = require('./commands/projects');
3
4
const { teamsList } = require('./commands/teams');
4
5
const { functionsListRuntimes } = require('./commands/functions');
@@ -126,7 +127,7 @@ const questionsPullProject = [
126
127
message: "Choose the project organization",
127
128
choices: async () => {
128
129
let client = await sdkForConsole(true);
129
- const { teams } = await paginate(teamsList, { parseOutput: false , sdk: client}, 100, 'teams');
130
+ const { teams } = await paginate(teamsList, { parseOutput: false, sdk: client }, 100, 'teams');
130
131
131
132
let choices = teams.map((team, idx) => {
132
133
return {
@@ -194,7 +195,7 @@ const questionsPullProject = [
194
195
choices: async (answers) => {
195
196
let response = await projectsList({
196
197
parseOutput: false,
197
- queries: [JSON.stringify({ method: 'equal', attribute:'teamId', values: [answers.organization.id] })],
198
+ queries: [JSON.stringify({ method: 'equal', attribute: 'teamId', values: [answers.organization.id] })],
198
199
})
199
200
let projects = response["projects"]
200
201
let choices = projects.map((project, idx) => {
@@ -245,7 +246,7 @@ const questionsPullFunction = [
245
246
id: runtime['$id'],
246
247
entrypoint: getEntrypoint(runtime['$id']),
247
248
ignore: getIgnores(runtime['$id']),
248
- commands : getInstallCommand(runtime['$id'])
249
+ commands: getInstallCommand(runtime['$id'])
249
250
},
250
251
}
251
252
})
@@ -280,6 +281,16 @@ const questionsPullCollection = [
280
281
];
281
282
282
283
const questionsLogin = [
284
+ {
285
+ type: "list",
286
+ name: "method",
287
+ message: "You're already logged in, what you like to do?",
288
+ choices: [
289
+ { name: 'Login to a different account', value: 'login' },
290
+ { name: 'Change to a different existed account', value: 'select' }
291
+ ],
292
+ when: () => globalConfig.getCurrentLogin() !== ''
293
+ },
283
294
{
284
295
type: "input",
285
296
name: "email",
@@ -290,6 +301,7 @@ const questionsLogin = [
290
301
}
291
302
return true;
292
303
},
304
+ when: (answers) => answers.method === 'login'
293
305
},
294
306
{
295
307
type: "password",
@@ -301,8 +313,33 @@ const questionsLogin = [
301
313
return "Please enter your password";
302
314
}
303
315
return true;
304
- }
316
+ },
317
+ when: (answers) => answers.method === 'login'
305
318
},
319
+ {
320
+ type: "list",
321
+ name: "accountId",
322
+ message: "Select an account to switch to",
323
+ choices() {
324
+ const logins = globalConfig.getLogins();
325
+ const current = globalConfig.getCurrentLogin();
326
+
327
+ const data = [];
328
+
329
+ const longestEmail = logins.reduce((prev, current) => (prev && prev.email > current.email) ? prev : current).email.length;
330
+
331
+ logins.forEach((login) => {
332
+ data.push({
333
+ value: login.id,
334
+ name: `${login.email.padEnd(longestEmail)} ${current === login.id ? chalk.green.bold('In use') : ' '.repeat(6)} ${login.endpoint}`,
335
+ });
336
+ })
337
+
338
+ return data;
339
+ },
340
+ when: (answers) => answers.method === 'select'
341
+ },
342
+
306
343
];
307
344
308
345
const questionsPushResources = [
@@ -494,7 +531,7 @@ const questionsListFactors = [
494
531
name: `Recovery code`,
495
532
value: 'recoveryCode'
496
533
}
497
- ].filter((ch) => factors[ch.value] === true);
534
+ ].filter((ch) => factors[ch.value] === true);
498
535
499
536
return choices;
500
537
}
0 commit comments