diff --git a/lib/do_wait_instance.js b/lib/do_wait_instance.js index 3b8a45b..7cb63a4 100644 --- a/lib/do_wait_instance.js +++ b/lib/do_wait_instance.js @@ -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}} 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;