( opts *SelectOptions, apps []dashboard.Application, )
| 170 | } |
| 171 | |
| 172 | func pickApplication( |
| 173 | opts *SelectOptions, |
| 174 | apps []dashboard.Application, |
| 175 | ) (*dashboard.Application, error) { |
| 176 | if opts.AppName != "" { |
| 177 | for i := range apps { |
| 178 | if apps[i].Name == opts.AppName { |
| 179 | return &apps[i], nil |
| 180 | } |
| 181 | } |
| 182 | return nil, fmt.Errorf("application %q not found", opts.AppName) |
| 183 | } |
| 184 | |
| 185 | if !opts.IO.CanPrompt() { |
| 186 | return nil, fmt.Errorf("--app-name is required in non-interactive mode") |
| 187 | } |
| 188 | |
| 189 | configuredProfiles := opts.Config.ConfiguredProfiles() |
| 190 | configuredAppIDs := make(map[string]string) |
| 191 | for _, p := range configuredProfiles { |
| 192 | configuredAppIDs[p.ApplicationID] = p.Name |
| 193 | } |
| 194 | |
| 195 | cs := opts.IO.ColorScheme() |
| 196 | appOptions := make([]string, len(apps)) |
| 197 | for i, app := range apps { |
| 198 | label := fmt.Sprintf("%s (%s)", app.ID, app.Name) |
| 199 | if profileName, ok := configuredAppIDs[app.ID]; ok { |
| 200 | appOptions[i] = fmt.Sprintf("%s %s", label, cs.Greenf("profile: %s", profileName)) |
| 201 | } else { |
| 202 | appOptions[i] = label |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | var selected int |
| 207 | err := prompt.SurveyAskOne( |
| 208 | &survey.Select{ |
| 209 | Message: "Select an application:", |
| 210 | Options: appOptions, |
| 211 | }, |
| 212 | &selected, |
| 213 | ) |
| 214 | if err != nil { |
| 215 | return nil, err |
| 216 | } |
| 217 | |
| 218 | return &apps[selected], nil |
| 219 | } |
no test coverage detected