Skip to content

Commit c20c65f

Browse files
committed
Improve CLI logout account prompt
1 parent 0a9d38b commit c20c65f

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
@@ -49,6 +49,7 @@ const {
4949
globalConfig,
5050
} = require("./lib/config.ts");
5151
const { listenForBrowserOpen } = require("./lib/auth/login.ts");
52+
const { questionsLogout } = require("./lib/questions.ts");
5253

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

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

0 commit comments

Comments
 (0)