UNPKG

ryuu

Version:

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

98 lines 4.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var inquirer = require("inquirer"); var chalk = require("chalk"); var login_1 = require("../util/login"); var log_1 = require("../util/log"); module.exports = function (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(function (cmd, options) { var login = login_1.Login.getCurrentLogin().instance; var previousLogins = login_1.Login.getPreviousLogins(); var prompts = []; switch (cmd) { case 'remove': if (!options['instance']) { prompts.push({ type: 'list', choices: function () { return previousLogins.map(function (item) { return item.instance; }); }, message: 'Domo instance on which to remove the token ' + chalk.grey('e.g. company.domo.com '), name: 'instance', default: login, }); } inquirer.prompt(prompts).then(function (answers) { answers.instance = options['instance'] || answers.instance; if (answers.instance) { new login_1.Login(answers.instance).removeDevToken(); log_1.log.ok("Token removed for ".concat(answers.instance), 'Future CLI commands to this instance will require username/password. \nUse the "domo token add" command to use another token.'); } }); break; case 'add': if (!options['instance']) { prompts.push({ type: 'list', choices: function () { var options = previousLogins.map(function (item) { return item.instance; }); options.push('new instance'); return options; }, message: 'Domo instance on which to set the token ' + chalk.grey('e.g. company.domo.com '), name: 'instance', default: login, }, { type: 'input', message: 'Domo instance ' + chalk.grey('e.g. company.domo.com '), name: 'newInstance', validate: function (input) { var acceptedDomains = [ 'domo.com', 'domotech.io', 'domorig.io', ]; if (acceptedDomains.some(function (domain) { return input.endsWith(domain); })) { return true; } return ('Please login using the full Domo instance. ' + chalk.grey('Example: "company.domo.com"')); }, when: function (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)', }); } inquirer.prompt(prompts).then(function (answers) { answers.instance = options['instance'] || answers.newInstance || answers.instance; answers.devtoken = options['token'] || answers.devtoken; var devToken = true; new login_1.Login(answers.instance).persistLogin(answers.devtoken, devToken); log_1.log.ok("Token set for ".concat(answers.instance), '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