inquirerer 2.0.4 → 2.0.5

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/esm/prompt.js CHANGED
@@ -151,6 +151,7 @@ export class Inquirerer {
151
151
  useDefaults;
152
152
  globalMaxLines;
153
153
  mutateArgs;
154
+ handledKeys = new Set();
154
155
  constructor(options) {
155
156
  const { noTty = false, input = process.stdin, output = process.stdout, useDefaults = false, globalMaxLines = 10, mutateArgs = true } = options ?? {};
156
157
  this.useDefaults = useDefaults;
@@ -392,6 +393,10 @@ export class Inquirerer {
392
393
  if (!Object.prototype.hasOwnProperty.call(argv, question.name)) {
393
394
  return;
394
395
  }
396
+ if (this.handledKeys.has(question.name)) {
397
+ return; // Already handled, skip further processing
398
+ }
399
+ this.handledKeys.add(question.name);
395
400
  switch (question.type) {
396
401
  case 'text':
397
402
  case 'number':
@@ -413,28 +418,31 @@ export class Inquirerer {
413
418
  handleOverridesForCheckboxOptions(argv, obj, question) {
414
419
  const options = this.sanitizeOptions(question);
415
420
  const input = argv[question.name];
416
- if (typeof input === 'string') {
417
- const found = options.filter(opt => opt.name === input || String(opt.value) === input);
418
- if (found.length) {
419
- obj[question.name] = found.map(f => {
420
- return {
421
- ...f,
422
- selected: true
423
- };
424
- });
425
- }
426
- }
427
- else if (Array.isArray(input)) {
428
- const found = options.filter(opt => input.includes(opt.name) || input.includes(String(opt.value)));
429
- if (found.length) {
430
- obj[question.name] = found.map(f => {
431
- return {
432
- ...f,
433
- selected: true
434
- };
421
+ // Normalize to array
422
+ const inputs = Array.isArray(input) ? input.map(String) : [String(input)];
423
+ // Set of matched values
424
+ const inputSet = new Set(inputs);
425
+ // Base list of processed options
426
+ const result = options.map(opt => ({
427
+ ...opt,
428
+ selected: inputSet.has(opt.name) || inputSet.has(String(opt.value))
429
+ }));
430
+ // Add extras if allowed
431
+ if (question.allowCustomOptions) {
432
+ const knownValues = new Set(options.map(opt => String(opt.value)));
433
+ const unknowns = inputs.filter(val => !knownValues.has(val));
434
+ for (const val of unknowns) {
435
+ result.push({
436
+ name: val,
437
+ value: val,
438
+ selected: true
435
439
  });
436
440
  }
437
441
  }
442
+ // Assign final result
443
+ obj[question.name] = question.returnFullResults
444
+ ? result
445
+ : result.filter(opt => opt.selected);
438
446
  }
439
447
  handleOverridesWithOptions(argv, obj, question) {
440
448
  if (typeof argv[question.name] === 'string') {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inquirerer",
3
- "version": "2.0.4",
3
+ "version": "2.0.5",
4
4
  "author": "Dan Lynch <pyramation@gmail.com>",
5
5
  "description": "inquirerer",
6
6
  "main": "index.js",
@@ -35,5 +35,5 @@
35
35
  "minimist": "^1.2.8"
36
36
  },
37
37
  "keywords": [],
38
- "gitHead": "fe5ce05ae6ffa6e93c6f91fc28b0d2be6de791fe"
38
+ "gitHead": "5302e9c3747a4b0ad21058538b96e848104cc41d"
39
39
  }
package/prompt.d.ts CHANGED
@@ -38,6 +38,7 @@ export declare class Inquirerer {
38
38
  private useDefaults;
39
39
  private globalMaxLines;
40
40
  private mutateArgs;
41
+ private handledKeys;
41
42
  constructor(options?: InquirererOptions);
42
43
  private clearScreen;
43
44
  private write;
package/prompt.js CHANGED
@@ -157,6 +157,7 @@ class Inquirerer {
157
157
  useDefaults;
158
158
  globalMaxLines;
159
159
  mutateArgs;
160
+ handledKeys = new Set();
160
161
  constructor(options) {
161
162
  const { noTty = false, input = process.stdin, output = process.stdout, useDefaults = false, globalMaxLines = 10, mutateArgs = true } = options ?? {};
162
163
  this.useDefaults = useDefaults;
@@ -398,6 +399,10 @@ class Inquirerer {
398
399
  if (!Object.prototype.hasOwnProperty.call(argv, question.name)) {
399
400
  return;
400
401
  }
402
+ if (this.handledKeys.has(question.name)) {
403
+ return; // Already handled, skip further processing
404
+ }
405
+ this.handledKeys.add(question.name);
401
406
  switch (question.type) {
402
407
  case 'text':
403
408
  case 'number':
@@ -419,28 +424,31 @@ class Inquirerer {
419
424
  handleOverridesForCheckboxOptions(argv, obj, question) {
420
425
  const options = this.sanitizeOptions(question);
421
426
  const input = argv[question.name];
422
- if (typeof input === 'string') {
423
- const found = options.filter(opt => opt.name === input || String(opt.value) === input);
424
- if (found.length) {
425
- obj[question.name] = found.map(f => {
426
- return {
427
- ...f,
428
- selected: true
429
- };
430
- });
431
- }
432
- }
433
- else if (Array.isArray(input)) {
434
- const found = options.filter(opt => input.includes(opt.name) || input.includes(String(opt.value)));
435
- if (found.length) {
436
- obj[question.name] = found.map(f => {
437
- return {
438
- ...f,
439
- selected: true
440
- };
427
+ // Normalize to array
428
+ const inputs = Array.isArray(input) ? input.map(String) : [String(input)];
429
+ // Set of matched values
430
+ const inputSet = new Set(inputs);
431
+ // Base list of processed options
432
+ const result = options.map(opt => ({
433
+ ...opt,
434
+ selected: inputSet.has(opt.name) || inputSet.has(String(opt.value))
435
+ }));
436
+ // Add extras if allowed
437
+ if (question.allowCustomOptions) {
438
+ const knownValues = new Set(options.map(opt => String(opt.value)));
439
+ const unknowns = inputs.filter(val => !knownValues.has(val));
440
+ for (const val of unknowns) {
441
+ result.push({
442
+ name: val,
443
+ value: val,
444
+ selected: true
441
445
  });
442
446
  }
443
447
  }
448
+ // Assign final result
449
+ obj[question.name] = question.returnFullResults
450
+ ? result
451
+ : result.filter(opt => opt.selected);
444
452
  }
445
453
  handleOverridesWithOptions(argv, obj, question) {
446
454
  if (typeof argv[question.name] === 'string') {
@@ -32,21 +32,18 @@ export interface AutocompleteQuestion extends BaseQuestion {
32
32
  type: 'autocomplete';
33
33
  options: (string | OptionValue)[];
34
34
  maxDisplayLines?: number;
35
- returnFullResults?: boolean;
36
- allowCustomOptions?: boolean;
37
35
  }
38
36
  export interface ListQuestion extends BaseQuestion {
39
37
  type: 'list';
40
38
  options: (string | OptionValue)[];
41
39
  maxDisplayLines?: number;
42
- returnFullResults?: boolean;
43
- allowCustomOptions?: boolean;
44
40
  }
45
41
  export interface CheckboxQuestion extends BaseQuestion {
46
42
  type: 'checkbox';
47
43
  options: (string | OptionValue)[];
48
44
  maxDisplayLines?: number;
49
45
  returnFullResults?: boolean;
46
+ allowCustomOptions?: boolean;
50
47
  default?: string[];
51
48
  }
52
49
  export interface TextQuestion extends BaseQuestion {