UNPKG

ryuu

Version:

Domo App Dev Studio CLI, The main tool used to create, edit, and publish app designs to Domo

91 lines 4.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const chalk = require('chalk'); const login_1 = require("../util/login"); const log_1 = require("../util/log"); const prompts_1 = require("../util/prompts"); module.exports = (program) => { program .command('token') .description('add or remove a developer token') .arguments('<cmd>') .option('-i, --instance <value>', 'Domo instance') .option('-t, --token <value>', 'dev token value used with token add') .action(async (cmd, options) => { const login = login_1.Login.getCurrentLogin().instance; const previousLogins = login_1.Login.getPreviousLogins(); const prompts = []; switch (cmd) { case 'remove': if (!options.instance) { const selectedInstance = await (0, prompts_1.createInstanceAutocomplete)('Domo instance on which to remove the token (e.g. company.domo.com)', false); options.instance = selectedInstance; } const instance = options.instance; if (instance) { new login_1.Login(instance).removeDevToken(); log_1.log.ok(`Token removed for ${instance}`, 'Use the `domo token add` command to use another token.'); } break; case 'add': if (!options.instance) { prompts.push({ type: 'list', choices: () => { const options = previousLogins.map(item => item.instance); options.push('new instance'); return options; }, message: 'Domo instance on which to set the token ' + '(e.g. company.domo.com)', name: 'instance', default: login, }, { type: 'input', message: 'Domo instance ' + chalk.grey('e.g. company.domo.com '), name: 'newInstance', validate: (input) => { const acceptedDomains = [ 'domo.com', 'domotech.io', 'domorig.io', ]; if (acceptedDomains.some(domain => input.endsWith(domain))) { return true; } return ('Please login using the full Domo instance. ' + 'Example: "company.domo.com"'); }, when: (answers) => { // only ask if the instance selector wasn't used or new one was selected return (!answers.instance || answers.instance === 'new instance'); }, }); } if (!options.token) { prompts.push({ name: 'devtoken', type: 'input', message: 'Token (can be found in the Admin section of Domo and pasted here)', }); } let instanceName = options.instance; let devtoken = options.token; if (!instanceName) { instanceName = await (0, prompts_1.createInstanceAutocomplete)('Domo instance on which to set the token (e.g. company.domo.com)', true); } if (!devtoken) { devtoken = await (0, prompts_1.createInput)('Token (can be found in the Admin section of Domo and pasted here)'); } const devToken = true; new login_1.Login(instanceName).persistLogin(devtoken, devToken); log_1.log.ok(`Token set for ${instanceName}`, 'Future CLI commands to this instance will not require username/password. \nUse the "domo token remove" command to undo this action.'); break; default: log_1.log.fail('Invalid option "' + cmd + '"\nValid options are "remove", and "add"'); } }); }; //# sourceMappingURL=token.js.map