diff --git a/cli/script/command-executor.ts b/cli/script/command-executor.ts index 5e37358c..5489bfd5 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; + } }); } @@ -1506,7 +1515,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` ); } diff --git a/cli/script/command-parser.ts b/cli/script/command-parser.ts index 43b8b391..c93a998d 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, @@ -450,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); }) @@ -1142,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 359ce1fc..b4dd1602 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;