diff --git a/packages/webpack-cli/lib/webpack-cli.js b/packages/webpack-cli/lib/webpack-cli.js index 5ab16847c01..e8f7b0a3146 100644 --- a/packages/webpack-cli/lib/webpack-cli.js +++ b/packages/webpack-cli/lib/webpack-cli.js @@ -1363,10 +1363,31 @@ class WebpackCLI { ); } + const flag = this.getBuiltInOptions().find( + (flag) => option.long === `--${flag.name}`, + ); + + if (flag && flag.configs) { + const possibleValues = flag.configs.reduce((accumulator, currentValue) => { + if (currentValue.values) { + return accumulator.concat(currentValue.values); + } else { + return accumulator; + } + }, []); + + if (possibleValues.length > 0) { + this.logger.raw( + `${bold("Possible values:")} ${JSON.stringify( + possibleValues.join(" | "), + )}`, + ); + } + } + this.logger.raw(""); // TODO implement this after refactor cli arguments - // logger.raw('Possible values: foo | bar'); // logger.raw('Documentation: https://webpack.js.org/option/name/'); } else { outputIncorrectUsageOfHelp(); diff --git a/test/help/__snapshots__/help.test.js.snap.devServer3.webpack5 b/test/help/__snapshots__/help.test.js.snap.devServer3.webpack5 index e64ba7ddde2..849523f1832 100644 --- a/test/help/__snapshots__/help.test.js.snap.devServer3.webpack5 +++ b/test/help/__snapshots__/help.test.js.snap.devServer3.webpack5 @@ -2540,6 +2540,20 @@ CLI documentation: https://webpack.js.org/api/cli/. Made with ♥ by the webpack team." `; +exports[`help should show help information using the "help --cache-type" option: stderr 1`] = `""`; + +exports[`help should show help information using the "help --cache-type" option: stdout 1`] = ` +"Usage: webpack --cache-type +Description: In memory caching. Filesystem caching. +Possible values: \\"memory | filesystem\\" + +To see list of all supported commands and options run 'webpack --help=verbose'. + +Webpack documentation: https://webpack.js.org/. +CLI documentation: https://webpack.js.org/api/cli/. +Made with ♥ by the webpack team." +`; + exports[`help should show help information using the "help --color" option: stderr 1`] = `""`; exports[`help should show help information using the "help --color" option: stdout 1`] = ` @@ -2560,6 +2574,7 @@ exports[`help should show help information using the "help --mode" option: stder exports[`help should show help information using the "help --mode" option: stdout 1`] = ` "Usage: webpack --mode Description: Defines the mode to pass to webpack. +Possible values: \\"development | production | none\\" To see list of all supported commands and options run 'webpack --help=verbose'. @@ -2571,6 +2586,7 @@ Made with ♥ by the webpack team." exports[`help should show help information using the "help --mode" option: stdout 2`] = ` "Usage: webpack --mode Description: Defines the mode to pass to webpack. +Possible values: \\"development | production | none\\" To see list of all supported commands and options run 'webpack --help=verbose'. @@ -2610,6 +2626,7 @@ exports[`help should show help information using the "help --stats" option: stde exports[`help should show help information using the "help --stats" option: stdout 1`] = ` "Usage: webpack --stats [value] Description: It instructs webpack on how to treat the stats e.g. verbose. +Possible values: \\"none | summary | errors-only | errors-warnings | minimal | normal | detailed | verbose\\" To see list of all supported commands and options run 'webpack --help=verbose'. @@ -2624,6 +2641,7 @@ exports[`help should show help information using the "help --target" option: std "Usage: webpack --target Short: webpack -t Description: Sets the build target e.g. node. +Possible values: \\"false\\" To see list of all supported commands and options run 'webpack --help=verbose'. @@ -2678,6 +2696,7 @@ exports[`help should show help information using the "help serve --mode" option: exports[`help should show help information using the "help serve --mode" option: stdout 1`] = ` "Usage: webpack serve --mode Description: Defines the mode to pass to webpack. +Possible values: \\"development | production | none\\" To see list of all supported commands and options run 'webpack --help=verbose'. diff --git a/test/help/__snapshots__/help.test.js.snap.devServer4.webpack5 b/test/help/__snapshots__/help.test.js.snap.devServer4.webpack5 index 3fa2c24e7bb..e76d76b08b9 100644 --- a/test/help/__snapshots__/help.test.js.snap.devServer4.webpack5 +++ b/test/help/__snapshots__/help.test.js.snap.devServer4.webpack5 @@ -2670,6 +2670,20 @@ CLI documentation: https://webpack.js.org/api/cli/. Made with ♥ by the webpack team." `; +exports[`help should show help information using the "help --cache-type" option: stderr 1`] = `""`; + +exports[`help should show help information using the "help --cache-type" option: stdout 1`] = ` +"Usage: webpack --cache-type +Description: In memory caching. Filesystem caching. +Possible values: \\"memory | filesystem\\" + +To see list of all supported commands and options run 'webpack --help=verbose'. + +Webpack documentation: https://webpack.js.org/. +CLI documentation: https://webpack.js.org/api/cli/. +Made with ♥ by the webpack team." +`; + exports[`help should show help information using the "help --color" option: stderr 1`] = `""`; exports[`help should show help information using the "help --color" option: stdout 1`] = ` @@ -2690,6 +2704,7 @@ exports[`help should show help information using the "help --mode" option: stder exports[`help should show help information using the "help --mode" option: stdout 1`] = ` "Usage: webpack --mode Description: Defines the mode to pass to webpack. +Possible values: \\"development | production | none\\" To see list of all supported commands and options run 'webpack --help=verbose'. @@ -2701,6 +2716,7 @@ Made with ♥ by the webpack team." exports[`help should show help information using the "help --mode" option: stdout 2`] = ` "Usage: webpack --mode Description: Defines the mode to pass to webpack. +Possible values: \\"development | production | none\\" To see list of all supported commands and options run 'webpack --help=verbose'. @@ -2740,6 +2756,7 @@ exports[`help should show help information using the "help --stats" option: stde exports[`help should show help information using the "help --stats" option: stdout 1`] = ` "Usage: webpack --stats [value] Description: It instructs webpack on how to treat the stats e.g. verbose. +Possible values: \\"none | summary | errors-only | errors-warnings | minimal | normal | detailed | verbose\\" To see list of all supported commands and options run 'webpack --help=verbose'. @@ -2754,6 +2771,7 @@ exports[`help should show help information using the "help --target" option: std "Usage: webpack --target Short: webpack -t Description: Sets the build target e.g. node. +Possible values: \\"false\\" To see list of all supported commands and options run 'webpack --help=verbose'. @@ -2808,6 +2826,7 @@ exports[`help should show help information using the "help serve --mode" option: exports[`help should show help information using the "help serve --mode" option: stdout 1`] = ` "Usage: webpack serve --mode Description: Defines the mode to pass to webpack. +Possible values: \\"development | production | none\\" To see list of all supported commands and options run 'webpack --help=verbose'. diff --git a/test/help/help.test.js b/test/help/help.test.js index 627a1ab9929..f7f556bcf8e 100644 --- a/test/help/help.test.js +++ b/test/help/help.test.js @@ -1,6 +1,6 @@ "use strict"; -const { run, normalizeStderr, normalizeStdout } = require("../utils/test-utils"); +const { run, normalizeStderr, normalizeStdout, isWebpack5 } = require("../utils/test-utils"); describe("help", () => { it('should show help information using the "--help" option', async () => { @@ -242,6 +242,18 @@ describe("help", () => { expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); }); + it('should show help information using the "help --cache-type" option', async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["help", "--cache-type"]); + + if (isWebpack5) { + expect(exitCode).toBe(0); + expect(normalizeStderr(stderr)).toMatchSnapshot("stderr"); + expect(normalizeStdout(stdout)).toMatchSnapshot("stdout"); + } else { + expect(exitCode).toBe(2); + } + }); + it('should show help information using the "help --no-stats" option', async () => { const { exitCode, stderr, stdout } = await run(__dirname, ["help", "--no-stats"]);