Skip to content

Commit

Permalink
Fixes open-cli-tools#33 - Add parameter/argument passthrough option
Browse files Browse the repository at this point in the history
Use -- to pass through arguments to the first command.

```
concurrently "echo foo" "echo bar" -- baz
```

```
echo foo baz
echo bar
```

Use the -a or --all option to pass through the arguments to all the commands.

```
concurrently "echo foo" "echo bar" --all -- baz
```

```
echo foo baz
echo bar baz
```
  • Loading branch information
thaggie committed Jan 25, 2017
1 parent 26abfed commit aae1889
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/main.js
Expand Up @@ -63,7 +63,7 @@ function main() {
function parseArgs() {
program
.version(require('../package.json').version)
.usage('[options] <command ...>')
.usage('[options] <command ...> [-- <args ...>]')
.option(
'-k, --kill-others',
'kill other processes if one exits or dies'
Expand Down Expand Up @@ -121,6 +121,12 @@ function parseArgs() {
'The option can be used to shorten long commands.\n' +
'Works only if prefix is set to "command". Default: ' +
config.prefixLength + '\n'
).option(
'-- <args ...>',
'pass through the <args> to the first command.\n'
).option(
'-a, --all',
'pass through the <args> to all the commands.\n'
);

program.on('--help', function() {
Expand All @@ -146,6 +152,10 @@ function parseArgs() {
' - Custom names and colored prefixes',
'',
' $ concurrently --prefix "[{name}]" --names "HTTP,WATCH" -c "bgBlue.bold,bgMagenta.bold" "npm run watch" "http-server"',
'',
' - Pass through arguments',
'',
' $ concurrently "echo hello" -- world',
''
];
console.log(help.join('\n'));
Expand All @@ -155,7 +165,13 @@ function parseArgs() {
console.log('');
});

program.parse(process.argv);
var passthroughArgumentsIndex = process.argv.indexOf('--');
if (passthroughArgumentsIndex !== -1) {
program.passthroughArguments = process.argv.slice(passthroughArgumentsIndex + 1);
program.parse(process.argv.slice(0, passthroughArgumentsIndex));
} else {
program.parse(process.argv);
}
}

function mergeDefaultsWithArgs(config) {
Expand All @@ -181,6 +197,10 @@ function run(commands) {
// Remove quotes.
cmd = stripCmdQuotes(cmd);

if ((index === 0 || config.all) && Array.isArray(config.passthroughArguments)) {
cmd += ' ' + config.passthroughArguments.join(' ');
}

var spawnOpts = config.raw ? {stdio: 'inherit'} : {};
if (IS_WINDOWS) {
spawnOpts.detached = false;
Expand Down
7 changes: 7 additions & 0 deletions test/test-functional.js
Expand Up @@ -83,6 +83,13 @@ describe('concurrently', function() {
});
});

it('can pass through an argument', () => {
return run('node ./src/main.js "exit" -- 1', {pipe: DEBUG_TESTS})
.then(function(exitCode) {
assert.strictEqual(exitCode, 1);
});
});

['SIGINT', 'SIGTERM'].forEach((signal) => {
if (IS_WINDOWS) {
console.log('IS_WINDOWS=true');
Expand Down

0 comments on commit aae1889

Please sign in to comment.