From b54e94ce95742b96174d706353207613e069a5cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 13 Jul 2017 19:58:32 +0300 Subject: [PATCH] MXS-1300: Add TSV output to MaxCtrl TSV output is a lot easier to parse compared to the pretty-printed Unicode. --- maxctrl/common.js | 46 +++++++++++++++++++++++++++++++++++++++++----- maxctrl/core.js | 7 ++++++- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/maxctrl/common.js b/maxctrl/common.js index eb1bbe2ee..b1114d512 100644 --- a/maxctrl/common.js +++ b/maxctrl/common.js @@ -145,7 +145,9 @@ module.exports = function() { logError(JSON.stringify(err, null, 4)) } else if (resp.statusCode == 200 && cb) { // Request OK, returns data - console.log(colors.yellow(host) + ':') + if (!argv.tsv) { + console.log(colors.yellow(host) + ':') + } cb(res) } else if (resp.statusCode == 204) { // Request OK, no data @@ -178,8 +180,33 @@ module.exports = function() { } } +var tsvopts = { + chars: { + 'top': '' , 'top-mid': '' , 'top-left': '' , 'top-right': '' + , 'bottom': '' , 'bottom-mid': '' , 'bottom-left': '' , 'bottom-right': '' + , 'left': '' , 'left-mid': '' , 'mid': '' , 'mid-mid': '' + , 'right': '' , 'right-mid': '' , 'middle': ' ' + }, + style: { + 'padding-left': 0, + 'padding-right': 0, + compact: true + }, + + +} + function getList() { - return new Table({ style: { head: ['cyan'] } }) + var opts = { + style: { head: ['cyan'] } + } + + if (this.argv.tsv) + { + opts = _.assign(opts, tsvopts) + } + + return new Table(opts) } // Creates a table-like array for output. The parameter is an array of header names @@ -189,9 +216,18 @@ function getTable(headobj) { headobj[i] = colors.cyan(headobj[i]) } - return new Table({ - head: headobj - }) + var opts + + if (this.argv.tsv) + { + opts = _.assign(opts, tsvopts) + } else { + opts = { + head: headobj + } + } + + return new Table(opts) } function pingMaxScale(host) { diff --git a/maxctrl/core.js b/maxctrl/core.js index 6e03bc098..21dacbe64 100644 --- a/maxctrl/core.js +++ b/maxctrl/core.js @@ -23,7 +23,7 @@ module.exports = function(argv) { return new Promise(function(resolve, reject) { program .version(maxctrl_version) - .group(['u', 'p', 'h', 's', 't'], 'Global Options:') + .group(['u', 'p', 'h', 's', 't', 'tsv'], 'Global Options:') .option('u', { alias:'user', global: true, @@ -56,6 +56,11 @@ module.exports = function(argv) { default: '10000', type: 'number' }) + .option('tsv', { + describe: 'Print tab separated output', + default: 'false', + type: 'boolean' + }) .command(require('./lib/list.js')) .command(require('./lib/show.js'))