Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: help and version functionality #1972

Merged
merged 7 commits into from Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/webpack-cli/lib/utils/arg-parser.js
Expand Up @@ -38,11 +38,11 @@ const argParser = (options, args, argsOnly = false, name = '') => {
// Prevent default behavior
parser.on('command:*', () => {});

// Use customized help output if available
parser.on('option:help', () => {
// Use customized help output
if (args.includes('--help')) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. It should be removed from there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same should be done for version too.

Screenshot at 2020-10-20 16-20-20

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update 👍🏻

runHelp(args);
process.exit(0);
});
}

// Allow execution if unknown arguments are present
parser.allowUnknownOption(true);
Expand Down
8 changes: 8 additions & 0 deletions test/help/help-flags.test.js
Expand Up @@ -21,6 +21,14 @@ describe('commands help', () => {
expect(stderr).toHaveLength(0);
});

it('should show help for --mode', () => {
const { stdout, stderr } = run(__dirname, ['--mode', '--help'], false);
expect(stdout).not.toContain(helpHeader);
expect(stdout).toContain('webpack --mode <development | production | none>');
expect(stdout).toContain('Defines the mode to pass to webpack');
expect(stderr).toHaveLength(0);
});

it('gives precedence to earlier flag in case of multiple flags', () => {
const { stdout, stderr } = run(__dirname, ['--help', '--entry', '--merge'], false);
expect(stdout).not.toContain(helpHeader);
Expand Down