fix(core): running just 'nx' should show help (#26871)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
Running `nx` errors

## Expected Behavior
`nx` show's help

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
This commit is contained in:
Craigory Coppola 2024-07-16 13:49:28 -04:00 committed by GitHub
parent 51f5fe4434
commit facfc147f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View File

@ -334,6 +334,12 @@ describe('Nx Commands', () => {
}
}, 300000);
});
it('should show help if no command provided', () => {
const output = runCLI('', { silenceError: true });
expect(output).toContain('Smart Monorepos · Fast CI');
expect(output).toContain('Commands:');
});
});
// TODO(colum): Change the fetcher to allow incremental migrations over multiple versions, allowing for beforeAll

View File

@ -1,4 +1,4 @@
import { CommandModule } from 'yargs';
import { CommandModule, showHelp } from 'yargs';
import {
withBatch,
withOverrides,
@ -40,6 +40,11 @@ export const yargsNxInfixCommand: CommandModule = {
const exitCode = await handleErrors(
(args.verbose as boolean) ?? process.env.NX_VERBOSE_LOGGING === 'true',
async () => {
// Yargs parses <target> as 'undefined' if running just 'nx'
if (!args.target || args.target === 'undefined') {
showHelp();
process.exit(1);
}
return (await import('./run-one')).runOne(
process.cwd(),
withOverrides(args, 0)