Skip to content

Commit 376735d

Browse files
committed
Add option to force logout if server is unreachable
1 parent 7a8f47d commit 376735d

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

cli/script/command-executor.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ export function execute(command: cli.ICommand) {
527527
return login(<cli.ILoginCommand>command);
528528

529529
case cli.CommandType.logout:
530-
return logout(command);
530+
return logout(<cli.ILogoutCommand>command);
531531

532532
case cli.CommandType.patch:
533533
return patch(<cli.IPatchCommand>command);
@@ -626,7 +626,7 @@ function loginWithExternalAuthentication(action: string, serverUrl?: string): Pr
626626
});
627627
}
628628

629-
function logout(command: cli.ICommand): Promise<void> {
629+
function logout(command: cli.ILogoutCommand): Promise<void> {
630630
return Q(<void>null)
631631
.then((): Promise<void> => {
632632
if (!connectionInfo.preserveAccessKeyOnLogout) {
@@ -642,6 +642,15 @@ function logout(command: cli.ICommand): Promise<void> {
642642
.then((): void => {
643643
sdk = null;
644644
deleteConnectionInfoCache();
645+
})
646+
.catch((error: any) => {
647+
if (command.force) {
648+
log(chalk.redBright("\nThere was an issue logging out from the server. Forcing logout by deleting local connection info.\n"));
649+
deleteConnectionInfoCache();
650+
log(chalk.yellowBright("Notice: Local session file was deleted, but the session ID might still exist on the server.\n"));
651+
} else {
652+
throw error;
653+
}
645654
});
646655
}
647656

cli/script/command-parser.ts

+10
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,13 @@ yargs
454454
yargs
455455
.usage(USAGE_PREFIX + " logout")
456456
.demand(/*count*/ 0, /*max*/ 0)
457+
.option("force", {
458+
alias: "f",
459+
default: null,
460+
demand: false,
461+
description: "Force logout, even if server is unreachable.",
462+
type: "boolean",
463+
})
457464
.example("logout", "Logs out and ends your current session");
458465
addCommonConfiguration(yargs);
459466
})
@@ -1146,6 +1153,9 @@ export function createCommand(): cli.ICommand {
11461153

11471154
case "logout":
11481155
cmd = { type: cli.CommandType.logout };
1156+
1157+
const logoutCommand = <cli.ILogoutCommand>cmd;
1158+
logoutCommand.force = argv["force"] as boolean;
11491159
break;
11501160

11511161
case "patch":

cli/script/types/cli.ts

+4
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ export interface ILoginCommand extends ICommand {
149149
accessKey: string;
150150
}
151151

152+
export interface ILogoutCommand extends ICommand {
153+
force: boolean
154+
}
155+
152156
export interface IPackageInfo {
153157
description?: string;
154158
label?: string;

0 commit comments

Comments
 (0)