From e0df274f06131e4f83b317168d666a39f9b29088 Mon Sep 17 00:00:00 2001 From: Esben von Buchwald Date: Thu, 9 Jan 2025 14:45:33 +0100 Subject: [PATCH 1/3] Fix logout instructions --- cli/script/command-executor.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/script/command-executor.ts b/cli/script/command-executor.ts index 5e37358..d1ead1f 100644 --- a/cli/script/command-executor.ts +++ b/cli/script/command-executor.ts @@ -1506,7 +1506,7 @@ function serializeConnectionInfo(accessKey: string, preserveAccessKeyOnLogout: b log( `\r\nSuccessfully logged-in. Your session file was written to ${chalk.cyan(configFilePath)}. You can run the ${chalk.cyan( - "code-push logout" + "code-push-standalone logout" )} command at any time to delete this file and terminate your session.\r\n` ); } From 4c6a2e32f34cc1d23fc98f92de1297f21d5e13a5 Mon Sep 17 00:00:00 2001 From: Esben von Buchwald Date: Thu, 9 Jan 2025 15:03:58 +0100 Subject: [PATCH 2/3] Fix login help --- cli/script/command-parser.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cli/script/command-parser.ts b/cli/script/command-parser.ts index 43b8b39..26aed9b 100644 --- a/cli/script/command-parser.ts +++ b/cli/script/command-parser.ts @@ -6,6 +6,7 @@ import * as cli from "../script/types/cli"; import * as chalk from "chalk"; import backslash = require("backslash"); import parseDuration = require("parse-duration"); +import AccountManager = require("./management-sdk"); const packageJson = require("../../package.json"); const ROLLOUT_PERCENTAGE_REGEX: RegExp = /^(100|[1-9][0-9]|[1-9])%?$/; @@ -428,10 +429,13 @@ yargs isValidCommandCategory = true; isValidCommand = true; yargs - .usage(USAGE_PREFIX + " login [options]") - .demand(/*count*/ 0, /*max*/ 1) //set 'max' to one to allow usage of serverUrl undocument parameter for testing - .example("login", "Logs in to the CodePush server") - .example("login --accessKey mykey", 'Logs in on behalf of the user who owns and created the access key "mykey"') + .usage(USAGE_PREFIX + " login [options]") + .demand(/*count*/ 0, /*max*/ 1) //set 'max' to one to allow usage of serverUrl + .example("login", `Logs in to the CodePush server on default serverUrl ${AccountManager.SERVER_URL}`) + .example( + "login https://codepush.example.com --accessKey mykey", + 'Logs in on behalf of the user who owns and created the access key "mykey", on the server running at https://codepush.example.com' + ) .option("accessKey", { alias: "key", default: null, From 8d241e3fb728a25bc6e89393852227adc0d05d04 Mon Sep 17 00:00:00 2001 From: Esben von Buchwald Date: Thu, 9 Jan 2025 15:22:00 +0100 Subject: [PATCH 3/3] Add option to force logout if server is unreachable --- cli/script/command-executor.ts | 13 +++++++++++-- cli/script/command-parser.ts | 10 ++++++++++ cli/script/types/cli.ts | 4 ++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/cli/script/command-executor.ts b/cli/script/command-executor.ts index d1ead1f..5489bfd 100644 --- a/cli/script/command-executor.ts +++ b/cli/script/command-executor.ts @@ -527,7 +527,7 @@ export function execute(command: cli.ICommand) { return login(command); case cli.CommandType.logout: - return logout(command); + return logout(command); case cli.CommandType.patch: return patch(command); @@ -626,7 +626,7 @@ function loginWithExternalAuthentication(action: string, serverUrl?: string): Pr }); } -function logout(command: cli.ICommand): Promise { +function logout(command: cli.ILogoutCommand): Promise { return Q(null) .then((): Promise => { if (!connectionInfo.preserveAccessKeyOnLogout) { @@ -642,6 +642,15 @@ function logout(command: cli.ICommand): Promise { .then((): void => { sdk = null; deleteConnectionInfoCache(); + }) + .catch((error: any) => { + if (command.force) { + log(chalk.redBright("\nThere was an issue logging out from the server. Forcing logout by deleting local connection info.\n")); + deleteConnectionInfoCache(); + log(chalk.yellowBright("Notice: Local session file was deleted, but the session ID might still exist on the server.\n")); + } else { + throw error; + } }); } diff --git a/cli/script/command-parser.ts b/cli/script/command-parser.ts index 26aed9b..c93a998 100644 --- a/cli/script/command-parser.ts +++ b/cli/script/command-parser.ts @@ -454,6 +454,13 @@ yargs yargs .usage(USAGE_PREFIX + " logout") .demand(/*count*/ 0, /*max*/ 0) + .option("force", { + alias: "f", + default: null, + demand: false, + description: "Force logout, even if server is unreachable.", + type: "boolean", + }) .example("logout", "Logs out and ends your current session"); addCommonConfiguration(yargs); }) @@ -1146,6 +1153,9 @@ export function createCommand(): cli.ICommand { case "logout": cmd = { type: cli.CommandType.logout }; + + const logoutCommand = cmd; + logoutCommand.force = argv["force"] as boolean; break; case "patch": diff --git a/cli/script/types/cli.ts b/cli/script/types/cli.ts index 359ce1f..b4dd160 100644 --- a/cli/script/types/cli.ts +++ b/cli/script/types/cli.ts @@ -149,6 +149,10 @@ export interface ILoginCommand extends ICommand { accessKey: string; } +export interface ILogoutCommand extends ICommand { + force: boolean +} + export interface IPackageInfo { description?: string; label?: string;