From fd0fa369ab15b0a3ef185f2eebf1a09565e9cc63 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Mon, 31 Aug 2015 15:16:44 -0700 Subject: [PATCH] triton wait: change signature to take states as an arg, and multiple separate instance name/id args --- lib/do_wait_instance.js | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) 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;