Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List clusters via optional flag #23

Merged
merged 3 commits into from
Dec 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions bin/esvm.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var join = require('path').join;
var flattenWith = require('../lib/flattenWith');
var explodeBy = require('../lib/explodeBy');
var mergeConfig = require('../lib/mergeConfig');
var formatter = require('../lib/formatClusters');

var rcloader = new RcLoader('.esvmrc');
var config = rcloader.for('.esvmrc');
Expand All @@ -34,12 +35,14 @@ commander
.option('-b, --branch', 'install from a branch release')
.option('-n, --nodes <n>', 'the number of nodes to start', parseInt)
.option('-c, --config <file>', 'the config file to use')
.option('-l, --list', 'list clusters in the config file')
.option('--cluster-name <name>', 'the cluster name to use')
.parse(process.argv);

var version = commander.args[0];
var options = {};


// If a config is passed via command line use that instead of the rcfile
if (commander.config) {
try {
Expand Down Expand Up @@ -98,6 +101,11 @@ if (commander.clusterName) {
options.clusterNameOverride = commander.clusterName;
}

// If given the list command and a config file, list clusters and exit
if (commander.config && commander.list) {
console.log(formatter(config.clusters))
return;
}

options.config = options.config;
var cluster = libesvm.createCluster(options);
Expand Down
29 changes: 29 additions & 0 deletions lib/formatClusters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var Table = require('cli-table');

module.exports = function (clusters) {
var table = new Table({
head: ['Cluster Name', 'Version', 'Plugins']
});

var clusterNames = Object.keys(clusters);
clusterNames.forEach(function (clusterName) {
var cluster = clusters[clusterName];

// append cluster name
var output = [clusterName];

// append branch/version
if (cluster.branch) output.push(cluster.branch + ' branch');
else if (cluster.version) output.push('v' + cluster.version);
else output.push('n/a');

// append plugins
if (cluster.plugins) output.push(cluster.plugins.join(','));
else output.push('');

// append cluster row to table
return table.push(output);
});

return table.toString();
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},
"dependencies": {
"cli-color": "^0.3.2",
"cli-table": "^0.3.1",
"commander": "^2.3.0",
"libesvm": "^3.2.0",
"lodash": "^2.4.1",
Expand Down