Skip to content

Commit f1eb2b7

Browse files
committed
chore: add flags for commands
1 parent c71a9f0 commit f1eb2b7

File tree

2 files changed

+71
-3
lines changed

2 files changed

+71
-3
lines changed

lib/groups/help.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const chalk = require('chalk');
2+
const commandLineUsage = require('command-line-usage');
23

34
class HelpGroup {
45
b() {
@@ -11,11 +12,21 @@ class HelpGroup {
1112
outputHelp(command=null) {
1213
if (command !== null) {
1314
const commands = require('../utils/commands').info;
15+
const { bold, underline } = chalk.white;
16+
const header = (head) => bold(underline(head));
17+
1418
const options = commands.find(cmd => (cmd.name === command || cmd.alias === command));
15-
const { bold } = chalk.white;
1619
const usage = chalk.keyword('orange')('webpack ' + options.usage);
1720
const description = options.description;
18-
process.stdout.write(`${bold('Usage')}: ${usage}\n${bold('Description')}: ${description}\n`);
21+
22+
process.stdout.write(`${header('Usage')}: ${usage}\n${header('Description')}: ${description}\n`);
23+
if (options.flags) {
24+
const flags = commandLineUsage({
25+
header: "Flags",
26+
optionList: options.flags
27+
});
28+
process.stdout.write(flags);
29+
}
1930
} else {
2031
process.stdout.write(this.run().outputOptions.help);
2132
}
@@ -32,7 +43,6 @@ class HelpGroup {
3243
run() {
3344
const { underline, bold } = chalk.white
3445
const o = s => chalk.keyword('orange')(s);
35-
const commandLineUsage = require('command-line-usage');
3646
const options = require('../utils/cli-flags');
3747
const title = bold('⬡ ') + underline('webpack') + bold(' ⬡');
3848
const desc = 'The build tool for modern web applications';

lib/utils/cli-flags.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,64 @@ module.exports = {
4343
type: String,
4444
usage: 'info [options] [output-format]',
4545
description: 'Outputs information about your system and dependencies',
46+
flags: [
47+
{
48+
name: 'output-json',
49+
type: Boolean,
50+
group: OUTPUT_GROUP,
51+
description: 'To get the output as JSON',
52+
},
53+
{
54+
name: 'output-markdown',
55+
type: Boolean,
56+
group: OUTPUT_GROUP,
57+
description: 'To get the output as markdown',
58+
},
59+
{
60+
name: 'help',
61+
type: Boolean,
62+
group: BASIC_GROUP,
63+
description: 'Shows help',
64+
},
65+
{
66+
name: 'version',
67+
type: Boolean,
68+
group: BASIC_GROUP,
69+
description: 'Show version number of webpack-cli',
70+
},
71+
{
72+
name: 'system',
73+
alias: 's',
74+
type: Boolean,
75+
group: BASIC_GROUP,
76+
description: 'System information ( OS, CPU )',
77+
},
78+
{
79+
name: 'binaries',
80+
alias: 'b',
81+
type: Boolean,
82+
group: BASIC_GROUP,
83+
description: 'Installed binaries (Node, yarn, npm)',
84+
},
85+
{
86+
name: 'browsers',
87+
type: Boolean,
88+
group: BASIC_GROUP,
89+
description: 'Installed web browsers',
90+
},
91+
{
92+
name: 'npmg',
93+
type: Boolean,
94+
group: BASIC_GROUP,
95+
description: 'Globally installed NPM packages ( webpack & webpack-cli only )',
96+
},
97+
{
98+
name: 'npmPackages',
99+
type: Boolean,
100+
group: BASIC_GROUP,
101+
description: 'Info about packages related to webpack installed in the project',
102+
},
103+
]
46104
},
47105
{
48106
name: 'serve',

0 commit comments

Comments
 (0)