UNPKG

@zendesk/zcli

Version:

Zendesk CLI is a single command line tool for all your zendesk needs

44 lines (43 loc) 1.75 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const core_1 = require("@oclif/core"); const chalk = require("chalk"); const zcli_core_1 = require("@zendesk/zcli-core"); const helpMessage_1 = require("../../utils/helpMessage"); class Remove extends core_1.Command { async run() { var _a; const { args } = await this.parse(Remove); const { account } = args; const secureStore = new zcli_core_1.SecureStore(); const keytar = await secureStore.loadKeytar(); if (!keytar) { console.log(chalk.yellow(`Failed to load secure credentials store: could not switch to ${account} profile.`), helpMessage_1.HELP_ENV_VARS); return; } const auth = new zcli_core_1.Auth({ secureStore }); const profiles = await auth.getSavedProfiles(); if (profiles && profiles.length) { const profileExists = !!((_a = profiles.filter((profile) => profile.account === account)) === null || _a === void 0 ? void 0 : _a.length); if (profileExists) { const { subdomain, domain } = (0, zcli_core_1.getProfileFromAccount)(account); await auth.setLoggedInProfile(subdomain, domain); console.log(chalk.green(`Switched to ${account} profile.`)); } else { console.log(chalk.red(`Failed to find ${account} profile.`)); } } else { console.log(chalk.red(`Failed to find ${account} profile.`)); } } } exports.default = Remove; Remove.description = 'switches to a profile'; Remove.args = [ { name: 'account', required: true } ]; Remove.examples = [ '$ zcli profiles:use [ACCOUNT]' ];