UNPKG

@hotglue/cli

Version:
82 lines (65 loc) 2.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handler = exports.desc = exports.command = exports.builder = void 0; var _debug = _interopRequireDefault(require("../../helpers/debug")); var _yaml = _interopRequireDefault(require("yaml")); var _cliTable = _interopRequireDefault(require("cli-table")); var _config = require("../../helpers/config"); var _print = require("../../helpers/print"); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const debug = (0, _debug.default)('commands:config:set'); const command = 'set <setting> <value>'; exports.command = command; const desc = 'Set configuration key-value pairs'; exports.desc = desc; const builder = async yargs => { debug('builder', command, yargs); yargs.option('setting', { describe: 'The configuration parameter you wish to set', type: 'string' }).option('value', { describe: "The configuration parameter's value", type: 'string' }); return yargs; }; exports.builder = builder; const handler = async argv => { debug('handler', command, argv); const { json, setting, value } = argv; const allowedSettings = ['apikey']; if (!allowedSettings.includes(setting)) { json ? (0, _print.printJSON)({ status: 'error', error: 'Invalid settings parameter' }) : console.error('Invalid settings parameter'); // throw new Error('Invalid settings parameter'); return; } try { const profileConfig = await (0, _config.getProfileConfig)(); if (profileConfig && profileConfig.config) !json && (0, _print.pp)('Updating profile config file...');else !json && (0, _print.pp)('Creating profile config file...'); const data = profileConfig && profileConfig.config ? { ...profileConfig.config, [setting]: value } : { [setting]: value }; const yamlData = _yaml.default.stringify(data); const filePath = profileConfig && profileConfig.filepath ? profileConfig.filepath : (0, _config.getProfileConfigFilePath)(); await (0, _config.writeConfigFile)(filePath, yamlData); json ? (0, _print.printJSON)({ status: 'success' }) : (0, _print.pp)('Done').pr(); } catch (err) { json ? (0, _print.printJSON)({ status: 'error', error: err }) : console.log(err); } }; exports.handler = handler;