2015-08-27 02:56:18 +03:00
|
|
|
/*
|
2015-09-04 21:12:20 +03:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2015 Joyent, Inc.
|
2015-08-27 02:56:18 +03:00
|
|
|
*
|
|
|
|
* `triton services ...`
|
|
|
|
*/
|
|
|
|
|
2015-09-03 06:24:08 +03:00
|
|
|
var tabula = require('tabula');
|
|
|
|
|
2015-08-27 02:56:18 +03:00
|
|
|
var common = require('./common');
|
|
|
|
|
2015-09-04 01:09:21 +03:00
|
|
|
// columns default without -o
|
|
|
|
var columnsDefault = 'name,endpoint';
|
|
|
|
|
|
|
|
// sort default with -s
|
|
|
|
var sortDefault = 'name';
|
|
|
|
|
2015-08-27 02:56:18 +03:00
|
|
|
function do_services(subcmd, opts, args, callback) {
|
|
|
|
if (opts.help) {
|
|
|
|
this.do_help('help', {}, [subcmd], callback);
|
|
|
|
return;
|
|
|
|
} else if (args.length !== 0) {
|
|
|
|
callback(new Error('invalid args: ' + args));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-04 01:09:21 +03:00
|
|
|
var columns = opts.o.split(',');
|
|
|
|
var sort = opts.s.split(',');
|
2015-09-03 06:24:08 +03:00
|
|
|
|
2015-09-04 21:04:45 +03:00
|
|
|
this.tritonapi.cloudapi.listServices(function (err, services) {
|
2015-08-27 02:56:18 +03:00
|
|
|
if (err) {
|
|
|
|
callback(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opts.json) {
|
2015-09-04 01:09:21 +03:00
|
|
|
console.log(JSON.stringify(services));
|
2015-08-27 02:56:18 +03:00
|
|
|
} else {
|
2015-09-04 01:09:21 +03:00
|
|
|
/*
|
|
|
|
* services are returned in the form of:
|
|
|
|
* {name: 'endpoint', name2: 'endpoint2', ...}
|
|
|
|
* we "normalize" them for use by tabula and JSON stream
|
|
|
|
* by making them an array
|
|
|
|
*/
|
|
|
|
var svcs = [];
|
|
|
|
Object.keys(services).forEach(function (key) {
|
|
|
|
svcs.push({
|
|
|
|
name: key,
|
|
|
|
endpoint: services[key]
|
|
|
|
});
|
|
|
|
});
|
2015-09-03 06:24:08 +03:00
|
|
|
tabula(svcs, {
|
|
|
|
skipHeader: opts.H,
|
|
|
|
columns: columns,
|
|
|
|
sort: sort,
|
|
|
|
dottedLookup: true
|
2015-08-27 02:56:18 +03:00
|
|
|
});
|
|
|
|
}
|
2015-09-03 06:24:08 +03:00
|
|
|
|
2015-08-27 02:56:18 +03:00
|
|
|
callback();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
do_services.options = [
|
|
|
|
{
|
|
|
|
names: ['help', 'h'],
|
|
|
|
type: 'bool',
|
|
|
|
help: 'Show this help.'
|
|
|
|
}
|
2015-09-04 01:09:21 +03:00
|
|
|
].concat(common.getCliTableOptions({
|
|
|
|
columnsDefault: columnsDefault,
|
|
|
|
sortDefault: sortDefault
|
|
|
|
}));
|
2015-09-03 06:24:08 +03:00
|
|
|
|
2016-06-09 00:13:16 +03:00
|
|
|
do_services.synopses = ['{{name}} {{cmd}}'];
|
|
|
|
|
|
|
|
do_services.help = [
|
|
|
|
'Show services information',
|
|
|
|
'',
|
|
|
|
'{{usage}}',
|
|
|
|
'',
|
|
|
|
'{{options}}'
|
|
|
|
].join('\n');
|
2015-08-27 02:56:18 +03:00
|
|
|
|
|
|
|
module.exports = do_services;
|