File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ " @gud/cli " : minor
3+ ---
4+
5+ Added support for select prompts when the option type is "number" and added type inference to the choice values based on the option type.
Original file line number Diff line number Diff line change 11import { Console } from 'node:console' ;
22import process from 'node:process' ;
3- import prompts , { type PromptObject , type PromptType } from 'prompts' ;
3+ import prompts , {
4+ type Choice ,
5+ type PromptObject ,
6+ type PromptType ,
7+ } from 'prompts' ;
48import { CliError , type CliErrorOptions } from 'src/core/errors' ;
9+ import type { OptionPrimitiveType , OptionType } from 'src/core/options/options' ;
510import type { KeyMap , Replace } from 'src/utils/types' ;
611
712// Errors //
@@ -58,14 +63,23 @@ export type PromptPrimitiveType<T extends PromptType = PromptType> =
5863 * @see [GitHub - terkelg/prompts - Prompt Objects](https://github.com/terkelg/prompts#-prompt-objects)
5964 * @group Client
6065 */
61- export type PromptParams < T extends PromptType = PromptType > = Replace <
66+ export type PromptParams <
67+ T extends PromptType = PromptType ,
68+ TOptionType extends OptionType = OptionType ,
69+ > = Replace <
6270 Omit < PromptObject , 'name' | 'separator' > ,
6371 {
6472 // make the message property required since prompts throws an error if it's
6573 // not defined.
6674 message : NonNullable < prompts . PromptObject [ 'message' ] > ;
6775 // make the type property optional since we'll default to 'text'
6876 type ?: T ;
77+ choices ?: Replace <
78+ Choice ,
79+ {
80+ value ?: OptionPrimitiveType < TOptionType > ;
81+ }
82+ > [ ] ;
6983 }
7084> ;
7185
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ export type OptionPromptTypeMap = KeyMap<
1515 {
1616 array : 'autocompleteMultiselect' | 'list' | 'multiselect' ;
1717 boolean : 'confirm' | 'toggle' ;
18- number : 'number' ;
18+ number : 'number' | 'select' ;
1919 secret : 'invisible' | 'password' ;
2020 string :
2121 | 'autocomplete'
@@ -32,7 +32,7 @@ export type OptionPromptType<T extends OptionType> = OptionPromptTypeMap[T];
3232// Functions + Function Types //
3333
3434export type OptionPromptParams < T extends OptionConfig = OptionConfig > = Replace <
35- PromptParams ,
35+ PromptParams < OptionPromptType < T [ 'type' ] > , T [ 'type' ] > ,
3636 {
3737 /**
3838 * The name of the option.
Original file line number Diff line number Diff line change @@ -34,7 +34,9 @@ type OptionGetterParams<T extends OptionConfig = OptionConfig> = Pick<
3434 /**
3535 * The prompt to show the user if no value is provided (optional).
3636 */
37- prompt ?: string | Omit < PromptParams < OptionPromptType < T [ 'type' ] > > , 'validate' > ;
37+ prompt ?:
38+ | string
39+ | Omit < PromptParams < OptionPromptType < T [ 'type' ] > , T [ 'type' ] > , 'validate' > ;
3840} ;
3941
4042/**
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ export type Eval<T> = { [K in keyof T]: T[K] } & unknown;
2929/**
3030 * Replace properties in `T` with properties in `U`.
3131 */
32- export type Replace < T , U > = Omit < T , keyof U > & U ;
32+ export type Replace < T , U extends Partial < T > | { } > = Omit < T , keyof U > & U ;
3333
3434/**
3535 * The opposite of {@linkcode Readonly<T>}. Make all properties in `T` mutable.
You can’t perform that action at this time.
0 commit comments