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: show default value in help output if available #2814

Merged
merged 2 commits into from Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion packages/webpack-cli/lib/webpack-cli.js
Expand Up @@ -1357,7 +1357,7 @@ class WebpackCLI {
this.logger.raw(`${bold("Description:")} ${option.description}`);
}

if (!option.negate && options.defaultValue) {
if (!option.negate && option.defaultValue) {
this.logger.raw(
`${bold("Default value:")} ${JSON.stringify(option.defaultValue)}`,
);
Expand Down
30 changes: 30 additions & 0 deletions test/api/CLI.test.js
Expand Up @@ -1699,4 +1699,34 @@ describe("CLI API", () => {
expect(command.helpInformation()).toContain("--no-boolean Negated description");
});
});

describe("custom help output", () => {
let consoleSpy;
let exitSpy;

beforeEach(async () => {
consoleSpy = jest.spyOn(global.console, "log");
exitSpy = jest.spyOn(process, "exit").mockImplementation(() => {});

cli.program.option("--color [value]", "any color", "blue");
await new Promise((resolve, reject) => {
try {
cli.run(["help", "--color"], { from: "user" });
resolve();
} catch (error) {
reject(error);
}
});
});

afterEach(async () => {
consoleSpy.mockRestore();
exitSpy.mockRestore();
});

it("should display help information", () => {
expect(exitSpy).toHaveBeenCalledWith(0);
expect(consoleSpy.mock.calls).toMatchSnapshot();
});
});
});
31 changes: 31 additions & 0 deletions test/api/__snapshots__/CLI.test.js.snap.webpack4
@@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CLI API custom help output should display help information 1`] = `
Array [
Array [
"Usage: webpack --color [value]",
],
Array [
"Description: any color",
],
Array [
"Default value: \\"blue\\"",
],
Array [
"",
],
Array [
"To see list of all supported commands and options run 'webpack --help=verbose'.
",
],
Array [
"Webpack documentation: https://webpack.js.org/.",
],
Array [
"CLI documentation: https://webpack.js.org/api/cli/.",
],
Array [
"Made with ♥ by the webpack team.",
],
]
`;
31 changes: 31 additions & 0 deletions test/api/__snapshots__/CLI.test.js.snap.webpack5
@@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CLI API custom help output should display help information 1`] = `
Array [
Array [
"Usage: webpack --color [value]",
],
Array [
"Description: any color",
],
Array [
"Default value: \\"blue\\"",
],
Array [
"",
],
Array [
"To see list of all supported commands and options run 'webpack --help=verbose'.
",
],
Array [
"Webpack documentation: https://webpack.js.org/.",
],
Array [
"CLI documentation: https://webpack.js.org/api/cli/.",
],
Array [
"Made with ♥ by the webpack team.",
],
]
`;