inquirerer 2.0.4 → 2.0.6
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 +37 -26
- package/package.json +2 -2
- package/prompt.d.ts +1 -0
- package/prompt.js +37 -26
- package/question/types.d.ts +1 -2
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,37 +418,43 @@ export class Inquirerer {
|
|
|
413
418
|
handleOverridesForCheckboxOptions(argv, obj, question) {
|
|
414
419
|
const options = this.sanitizeOptions(question);
|
|
415
420
|
const input = argv[question.name];
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
const
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
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
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
448
|
+
const input = argv[question.name];
|
|
449
|
+
if (typeof input !== 'string')
|
|
450
|
+
return;
|
|
451
|
+
const options = this.sanitizeOptions(question);
|
|
452
|
+
const found = options.find(opt => opt.name === input || String(opt.value) === input);
|
|
453
|
+
if (found) {
|
|
454
|
+
obj[question.name] = found.value;
|
|
455
|
+
}
|
|
456
|
+
else if (question.allowCustomOptions) {
|
|
457
|
+
obj[question.name] = input; // Store as-is
|
|
447
458
|
}
|
|
448
459
|
}
|
|
449
460
|
async handleQuestionType(question, ctx) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inquirerer",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
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": "
|
|
38
|
+
"gitHead": "e3b1d18ba6929731f2c662d451732307ec28ae75"
|
|
39
39
|
}
|
package/prompt.d.ts
CHANGED
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,37 +424,43 @@ class Inquirerer {
|
|
|
419
424
|
handleOverridesForCheckboxOptions(argv, obj, question) {
|
|
420
425
|
const options = this.sanitizeOptions(question);
|
|
421
426
|
const input = argv[question.name];
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
const
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
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
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
454
|
+
const input = argv[question.name];
|
|
455
|
+
if (typeof input !== 'string')
|
|
456
|
+
return;
|
|
457
|
+
const options = this.sanitizeOptions(question);
|
|
458
|
+
const found = options.find(opt => opt.name === input || String(opt.value) === input);
|
|
459
|
+
if (found) {
|
|
460
|
+
obj[question.name] = found.value;
|
|
461
|
+
}
|
|
462
|
+
else if (question.allowCustomOptions) {
|
|
463
|
+
obj[question.name] = input; // Store as-is
|
|
453
464
|
}
|
|
454
465
|
}
|
|
455
466
|
async handleQuestionType(question, ctx) {
|
package/question/types.d.ts
CHANGED
|
@@ -32,14 +32,12 @@ export interface AutocompleteQuestion extends BaseQuestion {
|
|
|
32
32
|
type: 'autocomplete';
|
|
33
33
|
options: (string | OptionValue)[];
|
|
34
34
|
maxDisplayLines?: number;
|
|
35
|
-
returnFullResults?: boolean;
|
|
36
35
|
allowCustomOptions?: boolean;
|
|
37
36
|
}
|
|
38
37
|
export interface ListQuestion extends BaseQuestion {
|
|
39
38
|
type: 'list';
|
|
40
39
|
options: (string | OptionValue)[];
|
|
41
40
|
maxDisplayLines?: number;
|
|
42
|
-
returnFullResults?: boolean;
|
|
43
41
|
allowCustomOptions?: boolean;
|
|
44
42
|
}
|
|
45
43
|
export interface CheckboxQuestion extends BaseQuestion {
|
|
@@ -47,6 +45,7 @@ export interface CheckboxQuestion extends BaseQuestion {
|
|
|
47
45
|
options: (string | OptionValue)[];
|
|
48
46
|
maxDisplayLines?: number;
|
|
49
47
|
returnFullResults?: boolean;
|
|
48
|
+
allowCustomOptions?: boolean;
|
|
50
49
|
default?: string[];
|
|
51
50
|
}
|
|
52
51
|
export interface TextQuestion extends BaseQuestion {
|