From e4d97c3a9b430470195494a227f2eabe2984a197 Mon Sep 17 00:00:00 2001 From: Gustavo Henke Date: Mon, 4 Nov 2024 22:58:55 +1100 Subject: [PATCH] bin: show help when no args are passed --- bin/concurrently.spec.ts | 5 +++++ bin/concurrently.ts | 12 +++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/bin/concurrently.spec.ts b/bin/concurrently.spec.ts index 2c00a519..dbe89191 100644 --- a/bin/concurrently.spec.ts +++ b/bin/concurrently.spec.ts @@ -117,6 +117,11 @@ it('has help command', async () => { expect(exit.code).toBe(0); }); +it('prints help when no arguments are passed', async () => { + const exit = await run('').exit; + expect(exit.code).toBe(0); +}); + describe('has version command', () => { const pkg = fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf-8'); const { version } = JSON.parse(pkg); diff --git a/bin/concurrently.ts b/bin/concurrently.ts index 25fe0457..08f65145 100755 --- a/bin/concurrently.ts +++ b/bin/concurrently.ts @@ -11,7 +11,7 @@ const version = String(readPackage().version); const epilogue = `For documentation and more examples, visit:\nhttps://github.com/open-cli-tools/concurrently/tree/v${version}/docs`; // Clean-up arguments (yargs expects only the arguments after the program name) -const args = yargs(hideBin(process.argv)) +const program = yargs(hideBin(process.argv)) .parserConfiguration({ // Avoids options that can be specified multiple times from requiring a `--` to pass commands 'greedy-arrays': false, @@ -209,8 +209,9 @@ const args = yargs(hideBin(process.argv)) .group(['i', 'default-input-target'], 'Input handling') .group(['k', 'kill-others-on-fail', 'kill-signal'], 'Killing other processes') .group(['restart-tries', 'restart-after'], 'Restarting') - .epilogue(epilogue) - .parseSync(); + .epilogue(epilogue); + +const args = program.parseSync(); // Get names of commands by the specified separator const names = (args.names || '').split(args.nameSeparator); @@ -218,6 +219,11 @@ const names = (args.names || '').split(args.nameSeparator); const additionalArguments = _.castArray(args['--'] ?? []).map(String); const commands = args.passthroughArguments ? args._ : args._.concat(additionalArguments); +if (!commands.length) { + program.showHelp(); + process.exit(); +} + concurrently( commands.map((command, index) => ({ command: String(command),