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
1 changed files with 23 additions and 8 deletions

View File

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