Skip to content

Commit 0860867

Browse files
committed
refactor: renaming login to sessions
1 parent 4641f61 commit 0860867

File tree

4 files changed

+34
-34
lines changed

4 files changed

+34
-34
lines changed

templates/cli/index.js.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const { commandDescriptions, cliConfig } = require("./lib/parser");
1212
const { client } = require("./lib/commands/generic");
1313
const inquirer = require("inquirer");
1414
{% if sdk.test != "true" %}
15-
const { login, logout, whoami, migrate } = require("./lib/commands/generic");
15+
const { login, logout, whoami } = require("./lib/commands/generic");
1616
const { init } = require("./lib/commands/init");
1717
const { pull } = require("./lib/commands/pull");
1818
const { push } = require("./lib/commands/push");

templates/cli/lib/commands/generic.js.twig

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ const loginCommand = async ({ email, password, endpoint, mfa, code }) => {
2020
if (answers.method === 'select') {
2121
const accountId = answers.accountId;
2222

23-
if (!globalConfig.getLoginIds().includes(accountId)) {
24-
throw Error('Login ID not found');
23+
if (!globalConfig.getSessionIds().includes(accountId)) {
24+
throw Error('Session ID not found');
2525
}
2626

2727
globalConfig.setCurrentSession(accountId);
@@ -164,13 +164,13 @@ const logout = new Command("logout")
164164
helpWidth: process.stdout.columns || 80
165165
})
166166
.action(actionRunner(async () => {
167-
const logins = globalConfig.getSessions();
167+
const sessions = globalConfig.getSessions();
168168
const current = globalConfig.getCurrentSession();
169169

170170
if (current === '') {
171171
return;
172172
}
173-
if (logins.length === 1) {
173+
if (sessions.length === 1) {
174174
await deleteSession(current);
175175
success();
176176

@@ -186,10 +186,10 @@ const logout = new Command("logout")
186186
}
187187
}
188188

189-
const leftLogins = globalConfig.getSessions();
189+
const leftSessions = globalConfig.getSessions();
190190

191-
if (leftLogins.length > 0 && leftLogins.filter(login => login.id === current).length !== 1) {
192-
const accountId = leftLogins[0].id;
191+
if (leftSessions.length > 0 && leftSessions.filter(session => session.id === current).length !== 1) {
192+
const accountId = leftSessions[0].id;
193193
globalConfig.setCurrentSession(accountId);
194194

195195
success(`Current account is ${accountId}`);
@@ -264,9 +264,9 @@ const client = new Command("client")
264264
}
265265

266266
if (reset !== undefined) {
267-
const logins = globalConfig.getSessions();
267+
const sessions = globalConfig.getSessions();
268268

269-
for (let accountId of logins.map(login => login.id)) {
269+
for (let accountId of sessions.map(session => session.id)) {
270270
globalConfig.setCurrentSession(accountId);
271271
await deleteSession(accountId);
272272
}

templates/cli/lib/config.js.twig

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -418,29 +418,29 @@ class Global extends Config {
418418
this.set(Global.PREFERENCE_CURRENT, endpoint);
419419
}
420420

421-
getLoginIds() {
421+
getSessionIds() {
422422
return Object.keys(this.data).filter((key) => !Global.IGNORE_ATTRIBUTES.includes(key));
423423
}
424424

425425
getSessions() {
426-
const logins = Object.keys(this.data).filter((key) => !Global.IGNORE_ATTRIBUTES.includes(key))
426+
const sessions = Object.keys(this.data).filter((key) => !Global.IGNORE_ATTRIBUTES.includes(key))
427427

428-
return logins.map((login) => {
428+
return sessions.map((session) => {
429429

430430
return {
431-
id: login,
432-
endpoint: this.data[login][Global.PREFERENCE_ENDPOINT],
433-
email: this.data[login][Global.PREFERENCE_EMAIL]
431+
id: session,
432+
endpoint: this.data[session][Global.PREFERENCE_ENDPOINT],
433+
email: this.data[session][Global.PREFERENCE_EMAIL]
434434
}
435435
})
436436
}
437437

438-
addSession(login, data) {
439-
this.set(login, data);
438+
addSession(session, data) {
439+
this.set(session, data);
440440
}
441441

442-
removeSession(login, data) {
443-
this.delete(login);
442+
removeSession(session) {
443+
this.delete(session);
444444
}
445445

446446
getEmail() {

templates/cli/lib/questions.js.twig

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -476,19 +476,19 @@ const questionsLogin = [
476476
name: "accountId",
477477
message: "Select an account to use",
478478
choices() {
479-
const logins = globalConfig.getSessions();
479+
const sessions = globalConfig.getSessions();
480480
const current = globalConfig.getCurrentSession();
481481

482482
const data = [];
483483

484-
const longestEmail = logins.reduce((prev, current) => (prev && (prev.email ?? '').length > (current.email ?? '').length) ? prev : current).email.length;
484+
const longestEmail = sessions.reduce((prev, current) => (prev && (prev.email ?? '').length > (current.email ?? '').length) ? prev : current).email.length;
485485

486-
logins.forEach((login) => {
487-
if (login.email) {
486+
sessions.forEach((session) => {
487+
if (session.email) {
488488
data.push({
489-
current: current === login.id,
490-
value: login.id,
491-
name: `${login.email.padEnd(longestEmail)} ${current === login.id ? chalk.green.bold('current') : ' '.repeat(6)} ${login.endpoint}`,
489+
current: current === session.id,
490+
value: session.id,
491+
name: `${session.email.padEnd(longestEmail)} ${current === session.id ? chalk.green.bold('current') : ' '.repeat(6)} ${session.endpoint}`,
492492
});
493493
}
494494
})
@@ -530,19 +530,19 @@ const questionsLogout = [
530530
message: "Select accounts to logout from",
531531
validate: (value) => validateRequired('account', value),
532532
choices() {
533-
const logins = globalConfig.getSessions();
533+
const sessions = globalConfig.getSessions();
534534
const current = globalConfig.getCurrentSession();
535535

536536
const data = [];
537537

538-
const longestEmail = logins.reduce((prev, current) => (prev && (prev.email ?? '').length > (current.email ?? '').length) ? prev : current).email.length;
538+
const longestEmail = sessions.reduce((prev, current) => (prev && (prev.email ?? '').length > (current.email ?? '').length) ? prev : current).email.length;
539539

540-
logins.forEach((login) => {
541-
if (login.email) {
540+
sessions.forEach((session) => {
541+
if (session.email) {
542542
data.push({
543-
current: current === login.id,
544-
value: login.id,
545-
name: `${login.email.padEnd(longestEmail)} ${current === login.id ? chalk.green.bold('current') : ' '.repeat(6)} ${login.endpoint}`,
543+
current: current === session.id,
544+
value: session.id,
545+
name: `${session.email.padEnd(longestEmail)} ${current === session.id ? chalk.green.bold('current') : ' '.repeat(6)} ${session.endpoint}`,
546546
});
547547
}
548548
})

0 commit comments

Comments
 (0)