* Get the option description to show in the list of options. * * @param {Option} option * @return {string}
(option)
| 324 | */ |
| 325 | |
| 326 | optionDescription(option) { |
| 327 | const extraInfo = []; |
| 328 | |
| 329 | if (option.argChoices) { |
| 330 | extraInfo.push( |
| 331 | // use stringify to match the display of the default value |
| 332 | `choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(', ')}`, |
| 333 | ); |
| 334 | } |
| 335 | if (option.defaultValue !== undefined) { |
| 336 | // default for boolean and negated more for programmer than end user, |
| 337 | // but show true/false for boolean option as may be for hand-rolled env or config processing. |
| 338 | const showDefault = |
| 339 | option.required || |
| 340 | option.optional || |
| 341 | (option.isBoolean() && typeof option.defaultValue === 'boolean'); |
| 342 | if (showDefault) { |
| 343 | extraInfo.push( |
| 344 | `default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`, |
| 345 | ); |
| 346 | } |
| 347 | } |
| 348 | // preset for boolean and negated are more for programmer than end user |
| 349 | if (option.presetArg !== undefined && option.optional) { |
| 350 | extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`); |
| 351 | } |
| 352 | if (option.envVar !== undefined) { |
| 353 | extraInfo.push(`env: ${option.envVar}`); |
| 354 | } |
| 355 | if (extraInfo.length > 0) { |
| 356 | const extraDescription = `(${extraInfo.join(', ')})`; |
| 357 | if (option.description) { |
| 358 | return `${option.description} ${extraDescription}`; |
| 359 | } |
| 360 | return extraDescription; |
| 361 | } |
| 362 | |
| 363 | return option.description; |
| 364 | } |
| 365 | |
| 366 | /** |
| 367 | * Get the argument description to show in the list of arguments. |
no test coverage detected