Skip to content

Commit

Permalink
bin: show help when no args are passed
Browse files Browse the repository at this point in the history
  • Loading branch information
gustavohenke committed Nov 4, 2024
1 parent 64b7e2a commit e4d97c3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 5 additions & 0 deletions bin/concurrently.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 9 additions & 3 deletions bin/concurrently.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -209,15 +209,21 @@ 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);

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),
Expand Down

0 comments on commit e4d97c3

Please sign in to comment.