Skip to content

Commit

Permalink
fix: throw error if help or version is supplied as an arg
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgeorge007 committed Aug 5, 2020
1 parent 87d0163 commit 8f5292a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
6 changes: 2 additions & 4 deletions packages/serve/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ export default function serve(...args: string[]): void {
const core = cli.getCoreFlags();

const parsedDevServerArgs = cli.argParser(devServer, args, true);
if (parsedDevServerArgs.unknownArgs.some((arg) => ['help', 'version'].includes(arg))) return;

const devServerArgs = parsedDevServerArgs.opts;
const parsedWebpackArgs = cli.argParser(core, parsedDevServerArgs.unknownArgs, true, process.title);
const webpackArgs = parsedWebpackArgs.opts;
Expand All @@ -30,9 +28,9 @@ export default function serve(...args: string[]): void {
parsedWebpackArgs.unknownArgs
.filter((e) => e)
.forEach((unknown) => {
logger.warn('Unknown argument:', unknown);
logger.error('Unknown argument:', unknown);
});
return;
process.exit(2);
}

cli.getCompiler(webpackArgs, core).then((compiler): void => {
Expand Down
6 changes: 3 additions & 3 deletions test/help/help-commands.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ const { run } = require('../utils/test-utils');
const helpHeader = 'The build tool for modern web applications';

describe('commands help', () => {
it('recognizes subcommands', () => {
const { stderr } = run(__dirname, ['help', 'serve'], false);
expect(stderr).not.toContain('Unknown argument: help');
it('throws error if supplied as an argument for subcommands', () => {
const { stderr } = run(__dirname, ['serve', 'help'], false);
expect(stderr).toContain('Unknown argument: help');
});

it('throws error for invalid command with --help flag', () => {
Expand Down

0 comments on commit 8f5292a

Please sign in to comment.