From e14aa729abac75f37799100306963010106b63ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Mon, 10 Jul 2017 11:13:37 +0300 Subject: [PATCH] MXS-1300: Add module commands to MaxCtrl Added inspection of module commands to MaxCtrl. The commands can't be called yet. --- client/maxctrl/common.js | 34 ++++++++++++++++++++++++++++++++++ client/maxctrl/lib/list.js | 6 ++++++ client/maxctrl/lib/show.js | 7 +++++++ 3 files changed, 47 insertions(+) diff --git a/client/maxctrl/common.js b/client/maxctrl/common.js index fd94ee614..ad09e67ef 100644 --- a/client/maxctrl/common.js +++ b/client/maxctrl/common.js @@ -53,6 +53,40 @@ module.exports = function() { }) } + // Request a part of a resource as a collection + this.getSubCollection = function (resource, subres, fields) { + + doRequest(resource, function(res) { + + var header = [] + + fields.forEach(function(i) { + header.push(Object.keys(i)) + }) + + var table = getTable(header) + + _.getPath(res.data, subres, []).forEach(function(i) { + row = [] + + fields.forEach(function(p) { + var v = _.getPath(i, p[Object.keys(p)[0]], '') + + if (Array.isArray(v) && typeof(v[0]) != 'object') { + v = v.join(', ') + } else if (typeof(v) == 'object') { + v = JSON.stringify(v, null, 4) + } + row.push(v) + }) + + table.push(row) + }) + + console.log(table.toString()) + }) + } + // Request a single resource and format it as a key-value list this.getResource = function (resource, fields) { diff --git a/client/maxctrl/lib/list.js b/client/maxctrl/lib/list.js index b18fb3ce8..1fe890e71 100644 --- a/client/maxctrl/lib/list.js +++ b/client/maxctrl/lib/list.js @@ -70,6 +70,12 @@ exports.builder = function(yargs) { {'Name':'id'} ]) }) + .command('commands', 'List module commands', {}, function() { + getCollection('maxscale/modules',[ + {'Module':'id'}, + {'Commands': 'attributes.commands[].id'} + ]) + }) .usage('Usage: list ') .help() .command('*', 'the default command', {}, () => { diff --git a/client/maxctrl/lib/show.js b/client/maxctrl/lib/show.js index 64e02917f..712c64006 100644 --- a/client/maxctrl/lib/show.js +++ b/client/maxctrl/lib/show.js @@ -93,6 +93,13 @@ exports.builder = function(yargs) { {'Uptime': 'attributes.uptime'} ]) }) + .command('commands ', 'Show module commands of a module', {}, function(argv) { + getSubCollection('maxscale/modules/' + argv.module, 'attributes.commands', [ + {'Command': 'id'}, + {'Parameters': 'attributes.parameters[].type'}, + {'Descriptions': 'attributes.parameters[].description'} + ]) + }) .usage('Usage: show ') .help() .command('*', 'the default command', {}, () => {