Skip to content

Commit 3e14be8

Browse files
committed
Improve CLI logout account prompt
1 parent f560bef commit 3e14be8

3 files changed

Lines changed: 34 additions & 9 deletions

File tree

templates/cli/lib/questions.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -910,26 +910,25 @@ export const questionsLogout: Question[] = [
910910
{
911911
type: "checkbox",
912912
name: "accounts",
913-
message: "Select accounts to logout from",
913+
message: "Select accounts to log out",
914914
validate: (value: any) => validateRequired("account", value),
915915
choices() {
916916
const sessions = globalConfig.getSessions();
917917
const current = globalConfig.getCurrentSession();
918918

919919
const data: Choice[] = [];
920920

921-
const longestEmail = sessions.reduce((prev: any, current: any) =>
922-
prev && (prev.email ?? "").length > (current.email ?? "").length
923-
? prev
924-
: current,
925-
).email.length;
926-
927921
sessions.forEach((session: any) => {
928922
if (session.email) {
923+
const isCurrent = current === session.id;
924+
const currentLabel = isCurrent
925+
? ` ${chalk.green.bold("(current)")}`
926+
: "";
929927
data.push({
930-
current: current === session.id,
928+
current: isCurrent,
931929
value: session.id,
932-
name: `${session.email.padEnd(longestEmail)} ${current === session.id ? chalk.green.bold("current") : " ".repeat(6)} ${session.endpoint}`,
930+
name: `${session.email}${currentLabel} - ${session.endpoint}`,
931+
short: `${session.email}${isCurrent ? " (current)" : ""}`,
933932
});
934933
}
935934
});

tests/e2e/Base.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ abstract class Base extends TestCase
260260
'auth:session-legacy:passed',
261261
'auth:session-has-auth:passed',
262262
'auth:plan-session-logout:passed',
263+
'auth:logout-question-choices:passed',
263264
'auth:restore-current-session-fallback:passed',
264265
'auth:poll-device-token-success:passed',
265266
'auth:poll-device-token-retry:passed',

tests/e2e/languages/cli/test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ const {
4848
normalizeCloudConsoleEndpoint,
4949
globalConfig,
5050
} = require("./lib/config.ts");
51+
const { questionsLogout } = require("./lib/questions.ts");
5152

5253
const extractFirstValue = (output) => {
5354
const firstLine =
@@ -901,6 +902,30 @@ async function runAuthChecks() {
901902
assert.deepEqual(planSessionLogout(["b1"]), ["b1"]);
902903
});
903904

905+
await authCheck("logout-question-choices", () => {
906+
globalConfig.clear();
907+
globalConfig.addSession("a1", {
908+
endpoint: "https://cloud.appwrite.io/v1",
909+
email: "a@b.com",
910+
});
911+
globalConfig.addSession("b1", {
912+
endpoint: "http://localhost/v1",
913+
email: "b@c.com",
914+
});
915+
globalConfig.setCurrentSession("b1");
916+
917+
const choices = questionsLogout[0].choices().map((choice) => ({
918+
...choice,
919+
name: stripAnsi(choice.name),
920+
}));
921+
922+
assert.equal(choices[0].value, "b1");
923+
assert.equal(choices[0].name, "b@c.com (current) - http://localhost/v1");
924+
assert.equal(choices[0].short, "b@c.com (current)");
925+
assert.equal(choices[1].name, "a@b.com - https://cloud.appwrite.io/v1");
926+
assert.equal(choices[1].short, "a@b.com");
927+
});
928+
904929
await authCheck("restore-current-session-fallback", () => {
905930
globalConfig.clear();
906931
globalConfig.addSession("s1", { endpoint: "http://localhost/v1" });

0 commit comments

Comments
 (0)