Skip to content

Commit

Permalink
fix(core): running just 'nx' should show help (#26871)
Browse files Browse the repository at this point in the history
<!-- 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 #
  • Loading branch information
AgentEnder authored Jul 16, 2024
1 parent 51f5fe4 commit facfc14
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions e2e/nx/src/misc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion packages/nx/src/command-line/run/command-object.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CommandModule } from 'yargs';
import { CommandModule, showHelp } from 'yargs';
import {
withBatch,
withOverrides,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit facfc14

Please sign in to comment.