From c629c51269fb41869950063541e055d7c7071c28 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Mon, 31 Oct 2016 01:02:03 -0500 Subject: [PATCH] Add --argument-passthrough --- README.md | 1 + src/main.js | 40 ++++++++++++++++++++++++++++++++++++++-- test/test-functional.js | 8 ++++++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 68e15656..61098ae9 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ Options: -r, --raw output only raw output of processes, disables prettifying and concurrently coloring -s, --success Return exit code of zero or one based on the success or failure of the "first" child to terminate, the "last" child, or succeed only if "all" child processes succeed. Default: all + --argument-passthrough pass arguments separated by `--` to each command -l, --prefix-length limit how many characters of the command is displayed in prefix. The option can be used to shorten long commands. diff --git a/src/main.js b/src/main.js index b7869e8c..9bb4bad7 100755 --- a/src/main.js +++ b/src/main.js @@ -45,7 +45,10 @@ var config = { color: true, // If true, the output will only be raw output of processes, nothing more - raw: false + raw: false, + + // If true, the arguments separated by `--` will be added to each command + argumentPassthrough: false }; function main() { @@ -57,7 +60,23 @@ function main() { parseArgs(); config = mergeDefaultsWithArgs(config); - run(program.args); + var commands = program.args.filter(function(arg) { + return arg[0] !== '-'; + }); + + var passthroughArguments = getArgsAfterDoubleDash(); + + var passthroughArgumentString = ''; + var shouldAddPassThroughArguments = config.argumentPassthrough && passthroughArguments.length > 0; + if(shouldAddPassThroughArguments) { + passthroughArgumentString = ' ' + passthroughArguments.join(' '); + } + + compiledCommands = commands.map(function(command) { + return command + passthroughArgumentString; + }); + + run(compiledCommands); } function parseArgs() { @@ -108,6 +127,10 @@ function parseArgs() { 'output only raw output of processes,' + ' disables prettifying and concurrently coloring' ) + .option( + '--argument-passthrough', + 'pass arguments separated by `--` to each command' + ) .option( '-s, --success ', 'Return exit code of zero or one based on the success or failure ' + @@ -374,6 +397,19 @@ function shortenText(text, length, cut) { return first + cut + last; } +function getArgsAfterDoubleDash() { + var foundDoubleDash = false; + var passthroughArguments = []; + process.argv.some(function(piece, index) { + if(piece === '--') { + passthroughArguments = process.argv.slice(index + 1); + // break + return true; + } + }); + return passthroughArguments; +} + function log(prefix, prefixColor, text) { logWithPrefix(prefix, prefixColor, text); } diff --git a/test/test-functional.js b/test/test-functional.js index 2613beed..19c883b7 100644 --- a/test/test-functional.js +++ b/test/test-functional.js @@ -83,6 +83,14 @@ describe('concurrently', function() { }); }); + it('--argument-passthrough should pass arguments to each command', () => { + // TODO: How can we test this? + return run('node ./src/main.js --argument-passthrough "echo test1" "echo test2" -- --foo', {pipe: DEBUG_TESTS}) + .then(function(exitCode) { + assert.strictEqual(exitCode, 0); + }); + }); + ['SIGINT', 'SIGTERM'].forEach((signal) => { if (IS_WINDOWS) { console.log('IS_WINDOWS=true');