Add debug setting to control needle options (#25)

diff --git a/bin/compose.js b/bin/compose.js
index e9b95ef..e426d13 100755
--- a/bin/compose.js
+++ b/bin/compose.js
@@ -24,6 +24,7 @@
 const path = require('path')
 
 const argv = minimist(process.argv.slice(2), {
+  string: ['debug'],
   boolean: ['version', 'ast', 'js'],
   alias: { version: 'v' }
 })
@@ -54,6 +55,7 @@
   console.error('  --ast                  only output the ast for the composition')
   console.error('  --js                   output the conductor action code for the composition')
   console.error('  -v, --version          output the composer version')
+  console.error('  --debug LIST           comma-separated list of debug flags (when using --js flag)')
   process.exit(1)
 }
 
@@ -67,7 +69,7 @@
   process.exit(422 - 256) // Unprocessable Entity
 }
 if (argv.js) {
-  console.log(conductor.generate(composition).action.exec.code)
+  console.log(conductor.generate(composition, argv.debug).action.exec.code)
 } else {
   if (argv.ast) composition = composition.ast
   console.log(JSON.stringify(composition, null, 4))
diff --git a/conductor.js b/conductor.js
index be3fb45..90e9e18 100644
--- a/conductor.js
+++ b/conductor.js
@@ -76,6 +76,17 @@
 
   const isObject = obj => typeof obj === 'object' && obj !== null && !Array.isArray(obj)
 
+  const needleOptions = (/needle<([^>]*)>/.exec(process.env.DEBUG || '') || [])[1]
+
+  function invoke (req) {
+    try {
+      if (needleOptions) req = Object.assign({}, req, JSON.parse(needleOptions))
+    } catch (err) {
+      console.err(`Ignoring invalid needle options: ${needleOptions}`)
+    }
+    return wsk.actions.invoke(req)
+  }
+
   function fork ({ p, node, index }, array, it) {
     const saved = p.params // save params
     p.s.state = index + node.return // return state
@@ -99,7 +110,7 @@
         params.$composer.redis = p.s.redis
         params.$composer.openwhisk = p.s.openwhisk
         params.$composer.join = { barrierId, position, count: array.length }
-        return wsk.actions.invoke({ name: process.env.__OW_ACTION_NAME, params }) // invoke branch
+        return invoke({ name: process.env.__OW_ACTION_NAME, params }) // invoke branch
           .then(({ activationId }) => { console.log(`barrierId: ${barrierId}, spawned position: ${position} with activationId: ${activationId}`) })
       }))).then(() => collect(p, barrierId), error => {
         console.error(error.body || error)
@@ -253,7 +264,7 @@
       p.params.$composer = { state: p.s.state, stack: [{ marker: true }].concat(p.s.stack), redis: p.s.redis, openwhisk: p.s.openwhisk }
       p.s.state = index + node.return
       if (!wsk) wsk = openwhisk(p.s.openwhisk)
-      return wsk.actions.invoke({ name: process.env.__OW_ACTION_NAME, params: p.params })
+      return invoke({ name: process.env.__OW_ACTION_NAME, params: p.params })
         .then(response => ({ method: 'async', activationId: response.activationId, sessionId: p.s.session }), error => {
           console.error(error) // invoke failed
           return { error: `Async combinator failed to invoke composition at AST node root${node.parent} (see log for details)` }