Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --argument-passthrough option #68

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -80,6 +80,7 @@ Options:

-r, --raw output only raw output of processes, disables prettifying and concurrently coloring
-s, --success <first|last|all> 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 <length> limit how many characters of the command is displayed in prefix.
The option can be used to shorten long commands.
Expand Down
40 changes: 38 additions & 2 deletions src/main.js
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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 <first|last|all>',
'Return exit code of zero or one based on the success or failure ' +
Expand Down Expand Up @@ -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);
}
Expand Down
8 changes: 8 additions & 0 deletions test/test-functional.js
Expand Up @@ -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');
Expand Down