Skip to content

Commit 7169149

Browse files
committed
allowCustomOptions on list/autocomplete
1 parent 5302e9c commit 7169149

2 files changed

Lines changed: 17 additions & 14 deletions

File tree

packages/inquirerer/src/prompt.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -588,23 +588,24 @@ export class Inquirerer {
588588
private handleOverridesWithOptions(
589589
argv: any,
590590
obj: any,
591-
question: AutocompleteQuestion | ListQuestion | CheckboxQuestion
591+
question: AutocompleteQuestion | ListQuestion
592592
): void {
593-
if (
594-
typeof argv[question.name] === 'string'
595-
) {
596-
const options = this.sanitizeOptions(question);
597-
const input = argv[question.name];
598-
599-
const found = options.find(
600-
opt => opt.name === input || String(opt.value) === input
601-
);
602-
603-
if (typeof found !== 'undefined') {
604-
obj[question.name] = found.value;
605-
}
593+
const input = argv[question.name];
594+
if (typeof input !== 'string') return;
595+
596+
const options = this.sanitizeOptions(question);
597+
598+
const found = options.find(
599+
opt => opt.name === input || String(opt.value) === input
600+
);
601+
602+
if (found) {
603+
obj[question.name] = found.value;
604+
} else if (question.allowCustomOptions) {
605+
obj[question.name] = input; // Store as-is
606606
}
607607
}
608+
608609

609610
private async handleQuestionType(question: Question, ctx: PromptContext): Promise<any> {
610611
this.keypress?.clearHandlers();

packages/inquirerer/src/question/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ export interface BaseQuestion {
3636
type: 'autocomplete';
3737
options: (string|OptionValue)[];
3838
maxDisplayLines?: number;
39+
allowCustomOptions?: boolean;
3940
}
4041

4142
export interface ListQuestion extends BaseQuestion {
4243
type: 'list';
4344
options: (string|OptionValue)[];
4445
maxDisplayLines?: number;
46+
allowCustomOptions?: boolean;
4547
}
4648

4749
export interface CheckboxQuestion extends BaseQuestion {

0 commit comments

Comments
 (0)