2015-08-26 01:30:25 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2015 Joyent Inc.
|
|
|
|
*
|
|
|
|
* `triton packages ...`
|
|
|
|
*/
|
|
|
|
|
|
|
|
var tabula = require('tabula');
|
|
|
|
|
|
|
|
var common = require('./common');
|
|
|
|
|
|
|
|
function do_packages (subcmd, opts, args, callback) {
|
|
|
|
if (opts.help) {
|
|
|
|
this.do_help('help', {}, [subcmd], callback);
|
|
|
|
return;
|
|
|
|
} else if (args.length > 1) {
|
|
|
|
callback(new Error('too many args: ' + args));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var columns = opts.o.trim().split(',');
|
|
|
|
var sort = opts.s.trim().split(',');
|
|
|
|
|
|
|
|
var validFilters = [
|
|
|
|
'name', 'memory', 'disk', 'swap', 'lwps', 'version', 'vcpus', 'group'
|
|
|
|
];
|
|
|
|
var listOpts;
|
|
|
|
try {
|
|
|
|
listOpts = common.kvToObj(args, validFilters);
|
|
|
|
} catch (e) {
|
|
|
|
callback(e);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.triton.cloudapi.listPackages(listOpts, function (err, packages) {
|
2015-08-26 02:46:14 +03:00
|
|
|
if (err) {
|
|
|
|
callback(err);
|
|
|
|
return;
|
|
|
|
}
|
2015-08-26 01:30:25 +03:00
|
|
|
if (opts.json) {
|
|
|
|
console.log(common.jsonStream(packages));
|
|
|
|
} else {
|
|
|
|
tabula(packages, {
|
|
|
|
skipHeader: opts.H,
|
|
|
|
columns: columns,
|
2015-08-26 06:53:48 +03:00
|
|
|
sort: sort
|
2015-08-26 01:30:25 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
do_packages.options = [
|
|
|
|
{
|
|
|
|
names: ['help', 'h'],
|
|
|
|
type: 'bool',
|
|
|
|
help: 'Show this help.'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
names: ['H'],
|
|
|
|
type: 'bool',
|
|
|
|
help: 'Omit table header row.'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
names: ['o'],
|
|
|
|
type: 'string',
|
2015-08-26 06:53:48 +03:00
|
|
|
default: 'id,name,default,memory,disk',
|
2015-08-26 01:30:25 +03:00
|
|
|
help: 'Specify fields (columns) to output.',
|
|
|
|
helpArg: 'field1,...'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
names: ['s'],
|
|
|
|
type: 'string',
|
|
|
|
default: 'name',
|
|
|
|
help: 'Sort on the given fields. Default is "name".',
|
|
|
|
helpArg: 'field1,...'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
names: ['json', 'j'],
|
|
|
|
type: 'bool',
|
|
|
|
help: 'JSON output.'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
do_packages.help = (
|
|
|
|
'List packgaes.\n'
|
|
|
|
+ '\n'
|
|
|
|
+ 'Usage:\n'
|
|
|
|
+ ' {{name}} packages\n'
|
|
|
|
+ '\n'
|
|
|
|
+ '{{options}}'
|
|
|
|
);
|
|
|
|
|
2015-08-26 02:19:19 +03:00
|
|
|
do_packages.aliases = ['pkgs'];
|
2015-08-26 01:30:25 +03:00
|
|
|
|
|
|
|
module.exports = do_packages;
|