@@ -45,7 +45,7 @@ export type CreateChooseFunctionOptions<T extends object> = {
4545
4646export type ChooseFunction < T extends object > = (
4747 command : APICommand < SelectFromListFlags > ,
48- itemIdOrNameFromArg ?: string ,
48+ itemIdOrIndexFromArg ?: string ,
4949 options ?: Partial < ChooseOptions < T > > ) => Promise < string >
5050
5151export const createChooseFn = < T extends object > (
@@ -55,20 +55,25 @@ export const createChooseFn = <T extends object>(
5555) : ChooseFunction < T > =>
5656 async (
5757 command : APICommand < SelectFromListFlags > ,
58- itemIdOrNameFromArg ?: string ,
58+ itemIdOrIndexFromArg ?: string ,
5959 options ?: Partial < ChooseOptions < T > > ,
6060 ) : Promise < string > => {
6161 const opts = chooseOptionsWithDefaults ( options )
6262
6363 // Listing items usually makes an API call which we only want to happen once so we do it
6464 // now and just use stub functions that return these items later as needed.
65- const items = await ( opts . listItems ?? listItems ) ( command )
66- const filteredItems = opts . listFilter ? items . filter ( opts . listFilter ) : items
67- const listItemsWrapper = async ( ) : Promise < T [ ] > => filteredItems
65+ let items : T [ ] | undefined = undefined
66+ const listItemsWrapper = async ( ) : Promise < T [ ] > => {
67+ if ( ! items ) {
68+ items = await ( opts . listItems ?? listItems ) ( command )
69+ }
70+ const filteredItems = opts . listFilter ? items . filter ( opts . listFilter ) : items
71+ return filteredItems
72+ }
6873
6974 const preselectedId = opts . allowIndex
70- ? await stringTranslateToId ( config , itemIdOrNameFromArg , listItemsWrapper )
71- : itemIdOrNameFromArg
75+ ? await stringTranslateToId ( config , itemIdOrIndexFromArg , listItemsWrapper )
76+ : itemIdOrIndexFromArg
7277
7378 const selectOptions : SelectOptions < T > = {
7479 preselectedId,
0 commit comments