@@ -179,7 +179,7 @@ func getRepoFromUserInput(cmd *cobra.Command) error {
179
179
return cmd .Flags ().Set ("repo" , repoInput )
180
180
}
181
181
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 ) {
183
183
var (
184
184
runtimeName string
185
185
err error
@@ -190,7 +190,7 @@ func ensureRuntimeName(ctx context.Context, args []string, allowManaged bool) (s
190
190
}
191
191
192
192
if ! store .Get ().Silent {
193
- runtimeName , err = getRuntimeNameFromUserSelect (ctx , allowManaged )
193
+ runtimeName , err = getRuntimeNameFromUserSelect (ctx , filter )
194
194
if err != nil {
195
195
return "" , err
196
196
}
@@ -203,7 +203,7 @@ func ensureRuntimeName(ctx context.Context, args []string, allowManaged bool) (s
203
203
return runtimeName , nil
204
204
}
205
205
206
- func getRuntimeNameFromUserSelect (ctx context.Context , allowManaged bool ) (string , error ) {
206
+ func getRuntimeNameFromUserSelect (ctx context.Context , filter func ( runtime * platmodel. Runtime ) bool ) (string , error ) {
207
207
runtimes , err := cfConfig .NewClient ().V2 ().Runtime ().List (ctx )
208
208
if err != nil {
209
209
return "" , err
@@ -213,35 +213,34 @@ func getRuntimeNameFromUserSelect(ctx context.Context, allowManaged bool) (strin
213
213
return "" , fmt .Errorf ("no runtimes were found" )
214
214
}
215
215
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 )
224
222
}
225
- rtDisplay = fmt .Sprintf ("%s (hosted)" , rtDisplay )
226
223
}
227
- runtimeNames = append (runtimeNames , rtDisplay )
224
+ } else {
225
+ filteredRuntimes = runtimes
228
226
}
229
227
230
228
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 }}" ,
232
232
}
233
233
234
234
labelStr := fmt .Sprintf ("%vSelect runtime%v" , CYAN , COLOR_RESET )
235
235
236
236
prompt := promptui.Select {
237
237
Label : labelStr ,
238
- Items : runtimeNames ,
238
+ Items : filteredRuntimes ,
239
239
Templates : templates ,
240
240
}
241
241
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
245
244
}
246
245
247
246
func getRuntimeNameFromUserInput () (string , error ) {
0 commit comments