triton wait: change signature to take states as an arg, and multiple separate instance name/id args

This commit is contained in:
Trent Mick 2015-08-31 15:16:44 -07:00
parent 022471afa7
commit fd0fa369ab

View File

@ -4,25 +4,32 @@
* `triton wait-instance ...` * `triton wait-instance ...`
*/ */
var format = require('util').format;
var common = require('./common'); var common = require('./common');
var errors = require('./errors');
function do_wait_instance(subcmd, opts, args, cb) { function do_wait_instance(subcmd, opts, args, cb) {
var self = this; var self = this;
if (opts.help) { if (opts.help) {
this.do_help('help', {}, [subcmd], cb); return this.do_help('help', {}, [subcmd], cb);
return; } else if (args.length < 1) {
} else if (args.length < 1 || args.length > 2) { return cb(new errors.UsageError(format(
cb(new Error('invalid args: ' + args)); 'incorrect number of args (%d): %s', args.length, args.join(' '))));
return;
} }
var ids = args;
var states = [];
opts.states.forEach(function (s) {
states = states.concat(s.trim().split(/\s*,\s*/g));
});
function log() { function log() {
if (!opts.quiet) if (!opts.quiet)
console.log.apply(console, arguments); console.log.apply(console, arguments);
} }
var ids = args[0].split(',');
var states = (args[1] || 'failed,running').split(',');
var done = 0; var done = 0;
var machines = {}; var machines = {};
@ -90,7 +97,7 @@ do_wait_instance.help = [
'Wait on instances moving to given states.', 'Wait on instances moving to given states.',
'', '',
'Usage:', 'Usage:',
' {{name}} wait <name|id> [<states>]', ' {{name}} wait [-s STATES] INSTANCE [INSTANCE ...]',
'', '',
'{{options}}', '{{options}}',
'Where "states" is a comma-separated list of target instance states,', 'Where "states" is a comma-separated list of target instance states,',
@ -108,6 +115,14 @@ do_wait_instance.options = [
type: 'bool', type: 'bool',
help: 'Disable all output.' help: 'Disable all output.'
}, },
{
names: ['states', 's'],
type: 'arrayOfString',
default: ['running', 'failed'],
helpArg: 'STATES',
help: 'Instance states on which to wait. Default is "running,failed".'
+ 'Values can be comma-separated or multiple uses of the option.'
},
]; ];
module.exports = do_wait_instance; module.exports = do_wait_instance;