diff --git a/bin/creature-start b/bin/creature-start index 1edd6aa..516b88f 100755 --- a/bin/creature-start +++ b/bin/creature-start @@ -3,36 +3,10 @@ const _ = require("lodash"); const path = x => require("../" + x); -const immutable = path("js/immutable"); const git = path("js/git"); const shell = path("js/shell"); const commander = path("js/commander"); -const branch = path("js/branch"); - -function validateCurrentBranch(dp) { - if (branch.isNonStandard(dp.branch.current)) { - throw `invalid base branch: ${dp.branch.current}`; - } else { - return dp; - } -} - -function validateFeatureName(dp) { - if (branch.isStandard(commander.featureName())) { - throw `invalid feature branch: ${commander.featureName()}`; - } else { - return dp; - } -} - -function setFeatureBranch(dp) { - const fb = [ - commander.prefix(), - dp.branch.current, - commander.featureName() - ].join("-"); - return immutable.set(dp, "branch.feature", fb); -} +const validate = path("js/validate"); function createFeatureBranch(dp) { return shell.pipeline([ @@ -44,14 +18,11 @@ function createFeatureBranch(dp) { ]); } -function toPromise(dp) { - return Promise.resolve(dp); -} - -const x = toPromise(commander.parse()) - .then(validateFeatureName) +commander + .start() .then(git.setCurrentBranch) - .then(validateCurrentBranch) - .then(setFeatureBranch) + .then(validate.currentIsStandardBranch) + .then(git.setFeatureBranch) + .then(validate.featureIsNotStandardBranch) .then(createFeatureBranch) .catch(err => console.error(err)); diff --git a/js/commander.js b/js/commander.js index 11aea3b..fb018eb 100644 --- a/js/commander.js +++ b/js/commander.js @@ -20,11 +20,25 @@ function prefix() { return process.env.FEATURE_USER || process.env.USER; } +function toPromise(dp) { + return Promise.resolve(dp); +} + +function echo(dp) { + console.log(JSON.stringify(dp)); + return dp; +} + +function start() { + return toPromise(parse()); +} + lib = { args, parse, featureName, - prefix + prefix, + start }; module.exports = lib; diff --git a/js/git.js b/js/git.js index abe701b..1742ac1 100644 --- a/js/git.js +++ b/js/git.js @@ -1,6 +1,7 @@ const _ = require("lodash"); const path = x => require("../" + x); +const commander = path("js/commander"); const immutable = path("js/immutable"); const shell = path("js/shell"); @@ -12,8 +13,18 @@ function setCurrentBranch(dp) { return shell.capture(cmd).then(x => immutable.set(dp, "branch.current", x)); } +function setFeatureBranch(dp) { + const fb = [ + commander.prefix(), + dp.branch.current, + commander.featureName() + ].join("-"); + return immutable.set(dp, "branch.feature", fb); +} + lib = { - setCurrentBranch + setCurrentBranch, + setFeatureBranch }; module.exports = lib; diff --git a/js/validate.js b/js/validate.js index e14ed0d..25c879f 100644 --- a/js/validate.js +++ b/js/validate.js @@ -1,23 +1,33 @@ +const path = x => require("../" + x); const branch = path("js/branch"); +const commander = path("js/commander"); let lib; -function validateCurrentBranch(dp) { +function currentIsStandardBranch(dp) { if (branch.isNonStandard(dp.branch.current)) { - throw `invalid base branch: ${dp.branch.current}`; + const branches = branch + .standard() + .sort() + .join(", "); + throw `ERROR: starting branch must be one of: ${branches}`; } else { return dp; } } -function validateFeatureName(dp) { +function featureIsNotStandardBranch(dp) { if (branch.isStandard(commander.featureName())) { - throw `invalid feature branch: ${commander.featureName()}`; + const branches = branch + .standard() + .sort() + .join(", "); + throw `ERROR: feature branch cannot be any of: ${branches}`; } else { return dp; } } -lib = { validateCurrentBranch, validateFeatureName }; +lib = { currentIsStandardBranch, featureIsNotStandardBranch }; module.exports = lib;