This repository has been archived on 2020-01-20. You can view files and clone it, but cannot push or open issues or pull requests.
node-spearhead/lib/do_instance.js

65 lines
1.2 KiB
JavaScript
Raw Normal View History

2015-08-26 03:27:46 +03:00
/*
* Copyright 2015 Joyent Inc.
*
* `triton instance ...`
*/
var common = require('./common');
function do_instance(subcmd, opts, args, callback) {
if (opts.help) {
this.do_help('help', {}, [subcmd], callback);
return;
} else if (args.length !== 1) {
callback(new Error('invalid args: ' + args));
return;
}
var id = args[0];
if (common.isUUID(id)) {
this.triton.cloudapi.getMachine(id, cb);
} else {
this.triton.getMachineByAlias(id, cb);
}
function cb(err, machine) {
if (err) {
callback(err);
return;
}
if (opts.json) {
console.log(JSON.stringify(machine));
} else {
console.log(JSON.stringify(machine, null, 4));
}
2015-08-26 03:27:46 +03:00
callback();
}
}
do_instance.options = [
{
names: ['help', 'h'],
type: 'bool',
help: 'Show this help.'
},
{
names: ['json', 'j'],
type: 'bool',
help: 'JSON output.'
}
];
do_instance.help = (
'Show a single instance.\n'
+ '\n'
+ 'Usage:\n'
+ ' {{name}} instance <alias|id>\n'
+ '\n'
+ '{{options}}'
);
do_instance.aliases = ['inst'];
module.exports = do_instance;