From d499696c8694e96ff3e63fe0f09382a2eb45503c Mon Sep 17 00:00:00 2001 From: ryanp Date: Wed, 26 Aug 2015 18:43:22 -0500 Subject: [PATCH] add untag and tag/untag all --- bin/jaws | 32 ++++++++++++++++++++++++++------ lib/commands/tag.js | 7 +++++-- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/bin/jaws b/bin/jaws index 05d325745..e6f0ae8bf 100755 --- a/bin/jaws +++ b/bin/jaws @@ -5,13 +5,13 @@ var JawsError = require('../lib/jaws-error'), JAWS = require('../lib/index.js'), program = require('commander'), - handleExit = require('../lib/utils').handleExit; + utils = require('../lib/utils'), + Promise = require('bluebird'), + handleExit = utils.handleExit; program .version(JAWS._meta.version); -//TODO: need to provide cli options vars to bypass input - program .command('new') .description('Creates a new JAWS project in the current working directory and creates an AWS CloudFormation ' + @@ -69,14 +69,34 @@ program } }); -//TODO: add untag feature -//TODO: add tag/untag all feature program .command('tag') + .option('-u, --untag', 'un-tag lambda') + .option('-a, --all', 'tag all lambda functions in project') + .option('-n, --untag-all', 'un-tag all lambda functions in project') .description('Tag a lambda function to be deployed the next time you run the deploy command for all' + ' tagged lambdas.') .action(function() { - handleExit(JAWS.tag()); + if (options.all || options.untagAll) { + var shouldTag = (options.all) ? true : false; + handleExit( + utils.findAllLambdas(utils.findProjectRootPath(process.cwd())) + .then(function(lJawsJsonPaths) { + var tagQueue = []; + if (!lJawsJsonPaths) { + throw new JawsError('Could not find any lambdas'); + } + + lJawsJsonPaths.forEach(function(ljp) { + tagQueue.push(JAWS.tag(ljp, shouldTag)); + }); + + return Promise.all(tagQueue); + }) + ); + } else { + handleExit(JAWS.tag(null, options.untag)); + } }); program diff --git a/lib/commands/tag.js b/lib/commands/tag.js index f0da63562..36bddf56c 100644 --- a/lib/commands/tag.js +++ b/lib/commands/tag.js @@ -18,9 +18,12 @@ module.exports = function(JAWS) { * Tag a lambda for deployment (set deploy = true) * * @param fullPathToJawsJson optional. Uses cwd by default + * @param {boolean} untag. default false * @returns {Promise} full path to jaws.json that was updated */ - JAWS.tag = function(fullPathToJawsJson) { + JAWS.tag = function(fullPathToJawsJson, untag) { + untag = (untag) ? true : false; + var jawsJsonPath = fullPathToJawsJson || path.join(process.cwd(), 'jaws.json'); return new Promise(function(resolve, reject) { @@ -33,7 +36,7 @@ module.exports = function(JAWS) { var jawsJson = require(jawsJsonPath); if (typeof jawsJson.lambda !== 'undefined') { - jawsJson.lambda.deploy = true; + jawsJson.lambda.deploy = !untag; fs.writeFileSync(jawsJsonPath, JSON.stringify(jawsJson, null, 2)); resolve(jawsJsonPath); } else {