Skip to content

Commit b358954

Browse files
authored
bin: show help when no args are passed (#513)
1 parent 64b7e2a commit b358954

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

bin/concurrently.spec.ts

+5
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ it('has help command', async () => {
117117
expect(exit.code).toBe(0);
118118
});
119119

120+
it('prints help when no arguments are passed', async () => {
121+
const exit = await run('').exit;
122+
expect(exit.code).toBe(0);
123+
});
124+
120125
describe('has version command', () => {
121126
const pkg = fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf-8');
122127
const { version } = JSON.parse(pkg);

bin/concurrently.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const version = String(readPackage().version);
1111
const epilogue = `For documentation and more examples, visit:\nhttps://github.com/open-cli-tools/concurrently/tree/v${version}/docs`;
1212

1313
// Clean-up arguments (yargs expects only the arguments after the program name)
14-
const args = yargs(hideBin(process.argv))
14+
const program = yargs(hideBin(process.argv))
1515
.parserConfiguration({
1616
// Avoids options that can be specified multiple times from requiring a `--` to pass commands
1717
'greedy-arrays': false,
@@ -209,15 +209,21 @@ const args = yargs(hideBin(process.argv))
209209
.group(['i', 'default-input-target'], 'Input handling')
210210
.group(['k', 'kill-others-on-fail', 'kill-signal'], 'Killing other processes')
211211
.group(['restart-tries', 'restart-after'], 'Restarting')
212-
.epilogue(epilogue)
213-
.parseSync();
212+
.epilogue(epilogue);
213+
214+
const args = program.parseSync();
214215

215216
// Get names of commands by the specified separator
216217
const names = (args.names || '').split(args.nameSeparator);
217218

218219
const additionalArguments = _.castArray(args['--'] ?? []).map(String);
219220
const commands = args.passthroughArguments ? args._ : args._.concat(additionalArguments);
220221

222+
if (!commands.length) {
223+
program.showHelp();
224+
process.exit();
225+
}
226+
221227
concurrently(
222228
commands.map((command, index) => ({
223229
command: String(command),

0 commit comments

Comments
 (0)