UNPKG

navy

Version:

Quick and powerful development environments using Docker and Docker Compose

72 lines (71 loc) 2.6 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.reconfigureIfNecessary = reconfigureIfNecessary; var _commander = 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.program.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); } const updated = { ...(await (0, _config.getConfig)()) }; updated[configProp] = value; await (0, _config.setConfig)(updated); await reconfigureIfNecessary(configProp); }); _commander.program.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.program.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); } const updated = { ...(await (0, _config.getConfig)()) }; updated[configProp] = null; await (0, _config.setConfig)(updated); await reconfigureIfNecessary(configProp); }); _commander.program.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.program.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.program.parse(process.argv); if (_commander.program.args.length === 0) { _commander.program.help(); }