( options: ParsedOptions, tokenDisplay: string, quiet: boolean, )
| 407 | } |
| 408 | |
| 409 | function buildNumericConfig( |
| 410 | options: ParsedOptions, |
| 411 | tokenDisplay: string, |
| 412 | quiet: boolean, |
| 413 | ): NumericInputConfig | undefined { |
| 414 | const min = parseFiniteNumber(options.minRaw); |
| 415 | const max = parseFiniteNumber(options.maxRaw); |
| 416 | const step = parseFiniteNumber(options.stepRaw); |
| 417 | const config: NumericInputConfig = {}; |
| 418 | |
| 419 | if (options.minRaw !== undefined) { |
| 420 | if (min === undefined) { |
| 421 | if (!quiet) |
| 422 | log.logWarning( |
| 423 | `QuickAdd: Ignoring invalid min in VALUE token "${tokenDisplay}".`, |
| 424 | ); |
| 425 | } else { |
| 426 | config.min = min; |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | if (options.maxRaw !== undefined) { |
| 431 | if (max === undefined) { |
| 432 | if (!quiet) |
| 433 | log.logWarning( |
| 434 | `QuickAdd: Ignoring invalid max in VALUE token "${tokenDisplay}".`, |
| 435 | ); |
| 436 | } else { |
| 437 | config.max = max; |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | if ( |
| 442 | config.min !== undefined && |
| 443 | config.max !== undefined && |
| 444 | config.max < config.min |
| 445 | ) { |
| 446 | if (!quiet) |
| 447 | log.logWarning( |
| 448 | `QuickAdd: Ignoring invalid numeric range in VALUE token "${tokenDisplay}"; max must be greater than or equal to min.`, |
| 449 | ); |
| 450 | delete config.min; |
| 451 | delete config.max; |
| 452 | } |
| 453 | |
| 454 | if (options.stepRaw !== undefined) { |
| 455 | if (step === undefined || step <= 0) { |
| 456 | if (!quiet) |
| 457 | log.logWarning( |
| 458 | `QuickAdd: Ignoring invalid step in VALUE token "${tokenDisplay}"; step must be greater than 0.`, |
| 459 | ); |
| 460 | } else { |
| 461 | config.step = step; |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | return Object.keys(config).length > 0 ? config : undefined; |
| 466 | } |
no test coverage detected