From 6e153547bbf5a78eec5dbbb0ecdbcacb3375cd39 Mon Sep 17 00:00:00 2001 From: Austen Collins Date: Tue, 8 Sep 2015 16:53:49 -0700 Subject: [PATCH] dash: start dash command --- bin/jaws | 8 ++++ lib/commands/dash.js | 110 +++++++++++++++++++++++++++++++++++++++++++ lib/utils/cli.js | 1 - 3 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 lib/commands/dash.js diff --git a/bin/jaws b/bin/jaws index b182ea916..e34f2451a 100755 --- a/bin/jaws +++ b/bin/jaws @@ -204,6 +204,14 @@ program } }); +program + .command('dash [stage] [region]') + .description('Check deployment status and deploy resources for a stage and region') + .action(function(stage, region) { + var theCmd = require('../lib/commands/dash'); + handleExit(theCmd.run(JAWS, stage, region)); + }); + program .command('logs ') .description('Get logs for the lambda function in the specified stage in your current working directory.') diff --git a/lib/commands/dash.js b/lib/commands/dash.js new file mode 100644 index 000000000..ed01b3945 --- /dev/null +++ b/lib/commands/dash.js @@ -0,0 +1,110 @@ +/** + * JAWS Command: dash + */ + +var JawsError = require('../jaws-error'), + JawsCLI = require('../utils/cli'), + Promise = require('bluebird'), + fs = require('fs'), + path = require('path'), + utils = require('../utils/index'), + tagCmd = require('./tag'); + + +/** + * Command Class + * @param projectJson + * @param stage + * @param region + * @constructor + */ +var CMD = function(projectJson, stage, region) { + this._projectJson = projectJson; + this._stage = stage; + this._region = region; +}; + +/** + * Prompt: Stage + */ +CMD.prototype._promptStage = Promise.method(function() { + + var _this = this; + + if (!_this._stage) { + + var stages = Object.keys(_this._projectJson.project.stages); + + // Check if project has stages + if (!stages.length) { + throw new JawsError('This project has no stages'); + } + + // Create Choices + var choices = []; + for (var i = 0; i < stages.length; i++) { + choices.push({ + key: (i + 1) + ') ', + value: stages[i], + }); + } + + return JawsCLI.select('Choose a stage: ', choices, false) + .then(function(results) { + _this._stage = results[0].value; + }); + } +}); + +/** + * Prompt: Region + */ +CMD.prototype._promptRegion = Promise.method(function() { + + var _this = this; + + if (!_this._region) { + var regions = _this._projectJson.project.stages[_this._stage].map(function(s) { + return s.region; + }); + + // Check if stage has regions + if (!regions.length) { + throw new JawsError('This stage has no regions'); + } + + // Create Choices + var choices = []; + for (var i = 0; i < regions.length; i++) { + choices.push({ + key: (i + 1) + ') ', + value: regions[i], + }); + } + + return JawsCLI.select('Choose a region within this stage: ', choices, false) + .then(function(results) { + _this._region = results[0].value; + }); + } +}); + +/** + * Run + */ +CMD.prototype.run = Promise.method(function() { + + var _this = this; + + return _this._promptStage() + .bind(_this) + .then(_this._promptRegion) + .then(function() { + console.log('this', _this); + }); +}); + +module.exports.run = function(JAWS, stage, region) { + var command = new CMD(JAWS._meta.projectJson, stage, region); + return command.run(); +}; \ No newline at end of file diff --git a/lib/utils/cli.js b/lib/utils/cli.js index 825b96343..a31389e10 100644 --- a/lib/utils/cli.js +++ b/lib/utils/cli.js @@ -233,6 +233,5 @@ module.exports.select = function(message, choices, multi, spacer) { // Initial Render Select._render(); - }); };