openwhisk-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tard...@apache.org
Subject [incubator-openwhisk-composer] branch master updated: Add compose --file and -o flags (#35)
Date Thu, 28 Mar 2019 01:27:18 GMT
This is an automated email from the ASF dual-hosted git repository.

tardieu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-composer.git


The following commit(s) were added to refs/heads/master by this push:
     new 2bd55af  Add compose --file and -o flags (#35)
2bd55af is described below

commit 2bd55afb38b883f3c88aa6fbabf51783184738ea
Author: Olivier Tardieu <tardieu@users.noreply.github.com>
AuthorDate: Wed Mar 27 21:27:14 2019 -0400

    Add compose --file and -o flags (#35)
---
 bin/compose.js | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/bin/compose.js b/bin/compose.js
index e426d13..a9cd01a 100755
--- a/bin/compose.js
+++ b/bin/compose.js
@@ -18,14 +18,15 @@
 
 const composer = require('../composer')
 const conductor = require('../conductor')
+const fs = require('fs')
 const json = require('../package.json')
 const minimist = require('minimist')
 const Module = require('module')
 const path = require('path')
 
 const argv = minimist(process.argv.slice(2), {
-  string: ['debug'],
-  boolean: ['version', 'ast', 'js'],
+  string: ['debug', 'o'],
+  boolean: ['version', 'ast', 'js', 'file'],
   alias: { version: 'v' }
 })
 
@@ -53,7 +54,9 @@ if (argv._.length !== 1 || path.extname(argv._[0]) !== '.js') {
   console.error('  compose composition.js [flags]')
   console.error('Flags:')
   console.error('  --ast                  only output the ast for the composition')
+  console.error('  --file                 write output to .json file with path and name matching
input file')
   console.error('  --js                   output the conductor action code for the composition')
+  console.error('  -o FILE                write output to FILE')
   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)
@@ -72,5 +75,13 @@ if (argv.js) {
   console.log(conductor.generate(composition, argv.debug).action.exec.code)
 } else {
   if (argv.ast) composition = composition.ast
-  console.log(JSON.stringify(composition, null, 4))
+  composition = JSON.stringify(composition, null, 4)
+  if (argv.o) {
+    fs.writeFileSync(argv.o, composition.concat('\n'), { encoding: 'utf8' })
+  } else if (argv.file) {
+    const { dir, name } = path.parse(argv._[0])
+    fs.writeFileSync(path.format({ dir, name, ext: '.json' }), composition.concat('\n'),
{ encoding: 'utf8' })
+  } else {
+    console.log(composition)
+  }
 }


Mime
View raw message