UNPKG

navy

Version:

Quick and powerful development environments using Docker and Docker Compose

90 lines (68 loc) 2.65 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.reconfigureIfNecessary = reconfigureIfNecessary; var _commander = _interopRequireDefault(require("commander")); var _config = require("../../config"); var _errors = require("../../errors"); var _reconfigure = require("../util/reconfigure"); const NAME_MAP = { 'default-navy': 'defaultNavy', 'external-ip': 'externalIP', 'tlsCa-dir': 'tlsRootCaDir' }; const configWhichNeedsReconfigure = ['externalIP']; async function reconfigureIfNecessary(configProp) { if (configWhichNeedsReconfigure.indexOf(configProp) === -1) { return; } await (0, _reconfigure.reconfigureAllNavies)(); } _commander.default.command('set <key> <value>').description('Sets the given config key').action(async (key, value) => { const configProp = NAME_MAP[key]; if (!configProp) { throw new _errors.NavyError('Invalid config key: ' + key); } await (0, _config.setConfig)({ ...(await (0, _config.getConfig)()), [configProp]: value }); await reconfigureIfNecessary(configProp); }); _commander.default.command('get <key>').description('Gets the given config by key').action(async key => { if (!NAME_MAP[key]) { throw new _errors.NavyError('Invalid config key: ' + key); } const config = await (0, _config.getConfig)(); console.log(config[NAME_MAP[key]]); }); _commander.default.command('rm <key>').description('Removes the current config value').action(async key => { const configProp = NAME_MAP[key]; if (!configProp) { throw new _errors.NavyError('Invalid config key: ' + key); } await (0, _config.setConfig)({ ...(await (0, _config.getConfig)()), [configProp]: null }); await reconfigureIfNecessary(configProp); }); _commander.default.command('ls').description('Lists all of the Navy config keys and values that have been set').action(async () => { const configKeys = Object.keys(NAME_MAP); const config = await (0, _config.getConfig)(); console.log(configKeys.map(key => `${key}=${config[NAME_MAP[key]] != null ? config[NAME_MAP[key]] : 'null'}`).join('\n')); }); _commander.default.command('json').description('Dumps out all Navy config as JSON').action(async () => { console.log(JSON.stringify(await (0, _config.getConfig)(), null, 2)); }); process.on('unhandledRejection', err => { if (err instanceof _errors.NavyError) { err.prettyPrint(); } else { console.error(err.stack); } }); _commander.default.parse(process.argv); if (_commander.default.args.length === 0) { _commander.default.help(); }