feature(show-config) add ability to show config values with --show-config

This commit is contained in:
coderaiser 2017-06-06 11:28:07 +03:00
parent 8132bbe3a3
commit 6ccb4f0be1
8 changed files with 89 additions and 2 deletions

View file

@ -71,6 +71,7 @@ Cloud Commander supports command line parameters:
| `-u, --username` | set username
| `-p, --password` | set password
| `-c, --config` | configuration file path
| `--show-config` | show config values
| `--editor` | set editor: "dword", "edward" or "deepword"
| `--packer` | set packer: "tar" or "zip"
| `--root` | set root directory

View file

@ -42,7 +42,8 @@ const args = require('minimist')(argv.slice(2), {
'console',
'terminal',
'one-panel-mode',
'html-dialogs'
'html-dialogs',
'show-config',
],
default: {
server : true,
@ -128,6 +129,9 @@ function main() {
validateRoot(options.root);
if (args['show-config'])
showConfig();
if (!args.save)
return start(options);
@ -167,6 +171,13 @@ function port(arg) {
exit('cloudcmd --port: should be a number');
}
function showConfig() {
const show = require('../server/show-config');
const data = show(config('*'));
console.log(data);
}
function readConfig(name) {
if (!name)
return;

View file

@ -26,6 +26,7 @@
"configDialog": true,
"console": true,
"terminal": false,
"terminalPath": ""
"terminalPath": "",
"showConfig": "false"
}

View file

@ -7,6 +7,7 @@
"-u, --username ": "set username",
"-p, --password ": "set password",
"-c, --config ": "configuration file path",
"--show-config ": "show config values",
"--editor ": "set editor: \"dword\", \"edward\" or \"deepword\"",
"--packer ": "set packer: \"tar\" or \"zip\"",
"--root ": "set root directory",

View file

@ -30,6 +30,7 @@ programs in browser from any computer, mobile or tablet device.
-u, --username set username
-p, --password set password
-c, --config configuration file path
--show-config show config values
--editor set editor: "dword", "edward" or "deepword"
--packer set packer: "tar" or "zip"
--root set root directory

View file

@ -154,6 +154,7 @@
"socket.io": "^2.0.1",
"spero": "^1.5.0",
"squad": "^1.1.3",
"table": "^4.0.1",
"try-catch": "^1.0.0",
"tryrequire": "^1.1.5",
"writejson": "^1.1.0"

35
server/show-config.js Normal file
View file

@ -0,0 +1,35 @@
'use strict';
const t = require('table');
const table = t.table;
const getBorderCharacters = t.getBorderCharacters;
module.exports = (config) => {
check(config);
const data = Object.keys(config).map((name) => {
return [name, config[name]];
});
if (!data.length)
return '';
return table(data, {
columns: {
1: {
width: 30,
truncate: 30,
}
},
border: getBorderCharacters('ramac'),
});
};
function check(config) {
if (!config)
throw Error('config could not be empty!');
if (typeof config !== 'object')
throw Error('config should be an object!');
}

View file

@ -0,0 +1,36 @@
'use strict';
const test = require('tape');
const showConfig = require('../../server/show-config');
test('cloudcmd: show-config: no arguments', (t) => {
t.throws(showConfig, /config could not be empty!/, 'should throw when no config');
t.end();
});
test('cloudcmd: show-config: bad arguments', (t) => {
const fn = () => showConfig('hello');
t.throws(fn, /config should be an object!/, 'should throw when config not object');
t.end();
});
test('cloudcmd: show-config: return', (t) => {
t.equal(showConfig({}), '', 'should return string');
t.end();
});
test('cloudcmd: show-config: return', (t) => {
const config = {
hello: 'world'
};
const result = [
'+-------+--------------------------------+\n',
'| hello | world |\n',
'+-------+--------------------------------+\n',
].join('');
t.equal(showConfig(config), result, 'should return table');
t.end();
});