UNPKG

@zendesk/zcli

Version:

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

48 lines (47 loc) 1.94 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 List extends core_1.Command { renderProfiles(profiles, loggedInProfile) { core_1.CliUx.ux.table(profiles, { account: { header: 'Accounts', get: row => { var _a; let log = row.account; if (row.account === (0, zcli_core_1.getAccount)((_a = loggedInProfile === null || loggedInProfile === void 0 ? void 0 : loggedInProfile.subdomain) !== null && _a !== void 0 ? _a : '', loggedInProfile === null || loggedInProfile === void 0 ? void 0 : loggedInProfile.domain)) { log = `${log} ${chalk.bold.green('<= active')}`; } return log; } } }, { printLine: this.log.bind(this) }); } async run() { 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 load profiles.'), helpMessage_1.HELP_ENV_VARS); return; } const auth = new zcli_core_1.Auth({ secureStore }); const profiles = await auth.getSavedProfiles(); if (profiles && profiles.length) { const loggedInProfile = await auth.getLoggedInProfile(); this.renderProfiles(profiles, loggedInProfile); } else { console.log('No profiles were found, use `zcli login` to create an active profile.'); } } } exports.default = List; List.description = 'lists all the profiles'; List.examples = [ '$ zcli profiles' ];