a quick 'triton package ID'; make 'cloudapi' command hidden from help output

This commit is contained in:
Trent Mick 2015-08-25 16:12:35 -07:00
parent 0987881887
commit e01babc05e
8 changed files with 156 additions and 19 deletions

21
etc/badger Normal file
View File

@ -0,0 +1,21 @@
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      
                                                      

View File

@ -65,7 +65,9 @@ function CLI() {
{ group: 'Images' }, { group: 'Images' },
'images', 'images',
'image', 'image',
{ group: 'Other', unmatched: true } { group: 'Packages' },
'packages',
'package'
] ]
}); });
} }
@ -111,9 +113,11 @@ CLI.prototype.do_instance_audit = require('./do_instance_audit');
// Packages // Packages
CLI.prototype.do_packages = require('./do_packages'); CLI.prototype.do_packages = require('./do_packages');
CLI.prototype.do_package = require('./do_package');
// Row Cloud API // Hidden commands
CLI.prototype.do_cloudapi = require('./do_cloudapi'); CLI.prototype.do_cloudapi = require('./do_cloudapi');
CLI.prototype.do_badger = require('./do_badger');

View File

@ -303,7 +303,7 @@ CloudAPI.prototype.getImage = function getImage(options, callback) {
options = {}; options = {};
} }
assert.object(options, 'options'); assert.object(options, 'options');
assert.uuid(options.id, 'ID'); assert.uuid(options.id, 'options.id');
assert.func(callback, 'callback'); assert.func(callback, 'callback');
var endpoint = this._path(format('/%s/images/%s', this.user, options.id)); var endpoint = this._path(format('/%s/images/%s', this.user, options.id));
@ -313,6 +313,37 @@ CloudAPI.prototype.getImage = function getImage(options, callback) {
}; };
// ---- packages
CloudAPI.prototype.listPackages = function listPackages(options, callback) {
var self = this;
if (typeof (options) === 'function') {
callback = options;
options = {};
}
var endpoint = self._path(format('/%s/packages', self.user), options);
self._request(endpoint, function (err, req, res, body) {
callback(err, body, res);
});
};
CloudAPI.prototype.getPackage = function getPackage(options, callback) {
if (callback === undefined) {
callback = options;
options = {};
}
assert.object(options, 'options');
assert.uuid(options.id, 'options.id');
assert.func(callback, 'callback');
var endpoint = this._path(format('/%s/packages/%s', this.user, options.id));
this._request(endpoint, function (err, req, res, body) {
callback(err, body, res);
});
};
// ---- machines // ---- machines
/** /**
@ -433,19 +464,6 @@ CloudAPI.prototype.listMachines = function listMachines(options, callback) {
); );
}; };
CloudAPI.prototype.listPackages = function listPackages(options, callback) {
var self = this;
if (typeof (options) === 'function') {
callback = options;
options = {};
}
var endpoint = self._path(format('/%s/packages', self.user), options);
self._request(endpoint, function (err, req, res, body) {
callback(err, body, res);
});
};
/** /**
* List machine audit (successful actions on the machine). * List machine audit (successful actions on the machine).

29
lib/do_badger.js Normal file
View File

@ -0,0 +1,29 @@
/*
* Copyright (c) 2015 Joyent Inc. All rights reserved.
*
* `triton package ...`
*/
var fs = require('fs');
var once = require('once');
var path = require('path');
function do_badger(subcmd, opts, args, callback) {
var callbackOnce = once(callback);
var badger = path.resolve(__dirname, '../etc/badger');
var input = fs.createReadStream(badger)
input.pipe(process.stdout);
input.on('error', function (err) {
callbackOnce(err);
});
input.on('end', function () {
callbackOnce();
});
};
do_badger.options = [];
do_badger.help = 'Rawr!';
do_badger.hidden = true;
module.exports = do_badger;

View File

@ -64,5 +64,7 @@ do_cloudapi.help = (
+ '{{options}}' + '{{options}}'
); );
do_cloudapi.hidden = true;
module.exports = do_cloudapi; module.exports = do_cloudapi;

View File

@ -5,7 +5,6 @@
*/ */
var format = require('util').format; var format = require('util').format;
var tabula = require('tabula');
var errors = require('./errors'); var errors = require('./errors');
@ -22,7 +21,7 @@ function do_image(subcmd, opts, args, callback) {
var getOpts = { var getOpts = {
id: args[0] id: args[0]
}; };
this.triton.cloudapi.getImage(getOpts, function onRes(err, img, res) { this.triton.cloudapi.getImage(getOpts, function onRes(err, img) {
if (err) { if (err) {
return callback(err); return callback(err);
} }

64
lib/do_package.js Normal file
View File

@ -0,0 +1,64 @@
/*
* Copyright (c) 2015 Joyent Inc. All rights reserved.
*
* `triton package ...`
*/
var format = require('util').format;
var errors = require('./errors');
function do_package(subcmd, opts, args, callback) {
if (opts.help) {
this.do_help('help', {}, [subcmd], callback);
return;
} else if (args.length !== 1) {
return callback(new errors.UsageError(format(
'incorrect number of args (%d): %s', args.length, args.join(' '))));
}
var getOpts = {
id: args[0]
};
this.triton.cloudapi.getPackage(getOpts, function onRes(err, pkg) {
if (err) {
return callback(err);
}
if (opts.json) {
console.log(JSON.stringify(pkg));
} else {
console.log(JSON.stringify(pkg, null, 4));
}
callback();
});
};
do_package.options = [
{
names: ['help', 'h'],
type: 'bool',
help: 'Show this help.'
},
{
names: ['json', 'j'],
type: 'bool',
help: 'JSON stream output.'
}
];
do_package.help = (
/* BEGIN JSSTYLED */
'Get a package.\n' +
'\n' +
'Note: Currently this dumps prettified JSON by default. That might change\n' +
'in the future. Use "-j" to explicitly get JSON output.\n' +
'\n' +
'Usage:\n' +
' {{name}} package [<options>] ID\n' +
'\n' +
'{{options}}'
/* END JSSTYLED */
);
module.exports = do_package;

View File

@ -8,7 +8,7 @@
"assert-plus": "0.1.5", "assert-plus": "0.1.5",
"backoff": "2.4.1", "backoff": "2.4.1",
"bunyan": "1.4.0", "bunyan": "1.4.0",
"cmdln": "3.2.1", "cmdln": "3.2.2",
"dashdash": "1.10.0", "dashdash": "1.10.0",
"extsprintf": "1.0.2", "extsprintf": "1.0.2",
"mkdirp": "0.5.1", "mkdirp": "0.5.1",