@@ -179,7 +179,7 @@ func getRepoFromUserInput(cmd *cobra.Command) error {
179179 return cmd .Flags ().Set ("repo" , repoInput )
180180}
181181
182- func ensureRuntimeName (ctx context.Context , args []string , allowManaged bool ) (string , error ) {
182+ func ensureRuntimeName (ctx context.Context , args []string , filter func ( runtime * platmodel. Runtime ) bool ) (string , error ) {
183183 var (
184184 runtimeName string
185185 err error
@@ -190,7 +190,7 @@ func ensureRuntimeName(ctx context.Context, args []string, allowManaged bool) (s
190190 }
191191
192192 if ! store .Get ().Silent {
193- runtimeName , err = getRuntimeNameFromUserSelect (ctx , allowManaged )
193+ runtimeName , err = getRuntimeNameFromUserSelect (ctx , filter )
194194 if err != nil {
195195 return "" , err
196196 }
@@ -203,7 +203,7 @@ func ensureRuntimeName(ctx context.Context, args []string, allowManaged bool) (s
203203 return runtimeName , nil
204204}
205205
206- func getRuntimeNameFromUserSelect (ctx context.Context , allowManaged bool ) (string , error ) {
206+ func getRuntimeNameFromUserSelect (ctx context.Context , filter func ( runtime * platmodel. Runtime ) bool ) (string , error ) {
207207 runtimes , err := cfConfig .NewClient ().V2 ().Runtime ().List (ctx )
208208 if err != nil {
209209 return "" , err
@@ -213,35 +213,34 @@ func getRuntimeNameFromUserSelect(ctx context.Context, allowManaged bool) (strin
213213 return "" , fmt .Errorf ("no runtimes were found" )
214214 }
215215
216- var runtimeNames []string
217-
218- for _ , rt := range runtimes {
219- rtDisplay := rt .Metadata .Name
220- if rt .Managed {
221- if ! allowManaged {
222- // preventing hosted runtimes to prompt
223- continue
216+ var filteredRuntimes []platmodel.Runtime
217+ if filter != nil {
218+ filteredRuntimes = make ([]platmodel.Runtime , 0 )
219+ for _ , rt := range runtimes {
220+ if filter (& rt ) {
221+ filteredRuntimes = append (filteredRuntimes , rt )
224222 }
225- rtDisplay = fmt .Sprintf ("%s (hosted)" , rtDisplay )
226223 }
227- runtimeNames = append (runtimeNames , rtDisplay )
224+ } else {
225+ filteredRuntimes = runtimes
228226 }
229227
230228 templates := & promptui.SelectTemplates {
231- Selected : "{{ . | yellow }} " ,
229+ Active : fmt .Sprintf ("%s {{ .Metadata.Name | underline }}{{ if ne .InstallationType \" HELM\" }}{{ printf \" (%%s)\" .InstallationType | underline }}{{ end }}" , promptui .IconSelect ),
230+ Inactive : " {{ .Metadata.Name }}{{ if ne .InstallationType \" HELM\" }}{{ printf \" (%s)\" .InstallationType }}{{ end }}" ,
231+ Selected : "{{ .Metadata.Name | yellow }}" ,
232232 }
233233
234234 labelStr := fmt .Sprintf ("%vSelect runtime%v" , CYAN , COLOR_RESET )
235235
236236 prompt := promptui.Select {
237237 Label : labelStr ,
238- Items : runtimeNames ,
238+ Items : filteredRuntimes ,
239239 Templates : templates ,
240240 }
241241
242- _ , result , err := prompt .Run ()
243- resultSplit := strings .Split (result , " " )
244- return resultSplit [0 ], err
242+ i , _ , err := prompt .Run ()
243+ return filteredRuntimes [i ].Metadata .Name , err
245244}
246245
247246func getRuntimeNameFromUserInput () (string , error ) {
0 commit comments