@oclif/core 2.9.1 → 2.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/parser/parse.js +19 -3
- package/package.json +1 -1
package/lib/parser/parse.js
CHANGED
|
@@ -257,16 +257,32 @@ class Parser {
|
|
|
257
257
|
}
|
|
258
258
|
return fws;
|
|
259
259
|
};
|
|
260
|
-
const addDefaultHelp = async (
|
|
260
|
+
const addDefaultHelp = async (fwsArray) => {
|
|
261
261
|
const valueReferenceForHelp = fwsArrayToObject(flagsWithAllValues.filter(fws => !fws.metadata?.setFromDefault));
|
|
262
|
-
return Promise.all(
|
|
262
|
+
return Promise.all(fwsArray.map(async (fws) => {
|
|
263
|
+
try {
|
|
264
|
+
if (fws.helpFunction) {
|
|
265
|
+
return {
|
|
266
|
+
...fws,
|
|
267
|
+
metadata: {
|
|
268
|
+
...fws.metadata,
|
|
269
|
+
defaultHelp: await fws.helpFunction?.(fws, valueReferenceForHelp, this.context),
|
|
270
|
+
},
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
catch {
|
|
275
|
+
// no-op
|
|
276
|
+
}
|
|
277
|
+
return fws;
|
|
278
|
+
}));
|
|
263
279
|
};
|
|
264
280
|
const fwsArrayToObject = (fwsArray) => Object.fromEntries(fwsArray.filter(fws => fws.value !== undefined)
|
|
265
281
|
.map(fws => [fws.inputFlag.name, fws.value]));
|
|
266
282
|
const flagTokenMap = this.mapAndValidateFlags();
|
|
267
283
|
const flagsWithValues = await Promise.all(Object.entries(this.input.flags)
|
|
268
284
|
// we check them if they have a token, or might have env, default, or defaultHelp. Also include booleans so they get their default value
|
|
269
|
-
.filter(([name, flag]) => flag.type === 'boolean' || flag.env || flag.default || 'defaultHelp' in flag || flagTokenMap.has(name))
|
|
285
|
+
.filter(([name, flag]) => flag.type === 'boolean' || flag.env || flag.default !== undefined || 'defaultHelp' in flag || flagTokenMap.has(name))
|
|
270
286
|
// match each possible flag to its token, if there is one
|
|
271
287
|
.map(([name, flag]) => ({ inputFlag: { name, flag }, tokens: flagTokenMap.get(name) }))
|
|
272
288
|
.map(fws => addValueFunction(fws))
|