Skip to content

Commit 8c6077c

Browse files
committed
move to cli
add resetDescription
1 parent ddb0c74 commit 8c6077c

3 files changed

Lines changed: 74 additions & 10 deletions

File tree

lib/cli.js

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ const getArguments = (schema = webpackSchema) => {
9797
*/
9898
const getDescription = path => {
9999
for (const { schema } of path) {
100-
if (schema.cli && schema.cli.helper) continue;
101-
if (schema.cliDescription) return schema.cliDescription;
100+
if (schema.cli) {
101+
if (schema.cli.helper) continue;
102+
if (schema.cli.description) return schema.cli.description;
103+
}
102104
if (schema.description) return schema.description;
103105
}
104106
};
@@ -110,8 +112,24 @@ const getArguments = (schema = webpackSchema) => {
110112
*/
111113
const getNegatedDescription = path => {
112114
for (const { schema } of path) {
113-
if (schema.cli && schema.cli.helper) continue;
114-
if (schema.negatedDescription) return schema.negatedDescription;
115+
if (schema.cli) {
116+
if (schema.cli.helper) continue;
117+
if (schema.cli.negatedDescription) return schema.cli.negatedDescription;
118+
}
119+
}
120+
};
121+
122+
/**
123+
*
124+
* @param {PathItem[]} path path in the schema
125+
* @returns {string | undefined} reset description
126+
*/
127+
const getResetDescription = path => {
128+
for (const { schema } of path) {
129+
if (schema.cli) {
130+
if (schema.cli.helper) continue;
131+
if (schema.cli.resetDescription) return schema.cli.resetDescription;
132+
}
115133
}
116134
};
117135

@@ -156,13 +174,17 @@ const getArguments = (schema = webpackSchema) => {
156174
const addResetFlag = path => {
157175
const schemaPath = path[0].path;
158176
const name = pathToArgumentName(`${schemaPath}.reset`);
159-
const description = getDescription(path);
177+
const description =
178+
getResetDescription(path) ||
179+
`Clear all items provided in '${schemaPath}' configuration. ${getDescription(
180+
path
181+
)}`;
160182
flags[name] = {
161183
configs: [
162184
{
163185
type: "reset",
164186
multiple: false,
165-
description: `Clear all items provided in '${schemaPath}' configuration. ${description}`,
187+
description,
166188
path: schemaPath
167189
}
168190
],

test/Cli.basictest.js

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,37 @@ describe("Cli", () => {
1111
type: "object",
1212
additionalProperties: false,
1313
properties: {
14+
"with-reset-description": {
15+
type: "array",
16+
items: {
17+
type: "string"
18+
},
19+
description: "original description",
20+
cli: {
21+
resetDescription: "custom reset"
22+
}
23+
},
1424
"with-cli-description": {
1525
type: "string",
1626
description: "original description",
17-
cliDescription: "description for CLI option"
27+
cli: {
28+
description: "description for CLI option"
29+
}
1830
},
1931
"with-negative-description": {
2032
type: "boolean",
2133
description: "original description",
22-
negatedDescription: "custom negative description"
34+
cli: {
35+
negatedDescription: "custom negative description"
36+
}
2337
},
2438
"with-both-cli-and-negative-description": {
2539
type: "boolean",
2640
description: "original description",
27-
cliDescription: "description for CLI option",
28-
negatedDescription: "custom negative description"
41+
cli: {
42+
description: "description for CLI option",
43+
negatedDescription: "custom negative description"
44+
}
2945
}
3046
}
3147
};

test/__snapshots__/Cli.basictest.js.snap

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8975,5 +8975,31 @@ Object {
89758975
"multiple": false,
89768976
"simpleType": "boolean",
89778977
},
8978+
"with-reset-description": Object {
8979+
"configs": Array [
8980+
Object {
8981+
"description": "original description",
8982+
"multiple": true,
8983+
"path": "with-reset-description[]",
8984+
"type": "string",
8985+
},
8986+
],
8987+
"description": "original description",
8988+
"multiple": true,
8989+
"simpleType": "string",
8990+
},
8991+
"with-reset-description-reset": Object {
8992+
"configs": Array [
8993+
Object {
8994+
"description": "custom reset",
8995+
"multiple": false,
8996+
"path": "with-reset-description",
8997+
"type": "reset",
8998+
},
8999+
],
9000+
"description": "custom reset",
9001+
"multiple": false,
9002+
"simpleType": "boolean",
9003+
},
89789004
}
89799005
`;

0 commit comments

Comments
 (0)