diff --git a/e2e/nx/src/misc.test.ts b/e2e/nx/src/misc.test.ts index 47e890021a..07a7a6a69b 100644 --- a/e2e/nx/src/misc.test.ts +++ b/e2e/nx/src/misc.test.ts @@ -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 diff --git a/packages/nx/src/command-line/run/command-object.ts b/packages/nx/src/command-line/run/command-object.ts index 120c2093b4..4acdf18be1 100644 --- a/packages/nx/src/command-line/run/command-object.ts +++ b/packages/nx/src/command-line/run/command-object.ts @@ -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 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)