Use the application lister in run
@@ -37,7 +37,6 @@ import (
"github.com/thestormforge/optimize-controller/v2/cli/internal/commands/initialize"
"github.com/thestormforge/optimize-controller/v2/cli/internal/commands/run/internal"
versioncmd "github.com/thestormforge/optimize-controller/v2/cli/internal/commands/version"
- "github.com/thestormforge/optimize-go/pkg/api"
applications "github.com/thestormforge/optimize-go/pkg/api/applications/v2"
"github.com/thestormforge/optimize-go/pkg/config"
corev1 "k8s.io/api/core/v1"
@@ -252,17 +251,18 @@ func (o *Options) listStormForgeTestCaseNames() tea.Msg {
// listApplicationNames returns a list of applications.
func (o *Options) listApplicationNames() tea.Msg {
ctx := context.TODO()
- appList, err := o.ApplicationsAPI.ListApplications(ctx, applications.ApplicationListQuery{})
+ msg := internal.ApplicationMsg{}
+
+ l := applications.Lister{API: o.ApplicationsAPI}
+ q := applications.ApplicationListQuery{}
+ err := l.ForEachApplication(ctx, q, func(item *applications.ApplicationItem) error {
+ msg = append(msg, fmt.Sprintf("%-32s (%s)", item.Title(), item.Name))
+ return nil
+ })
if err != nil {
return err
}
- msg := make(internal.ApplicationMsg, len(appList.Applications))
-
- for i := range appList.Applications {
- msg[i] = fmt.Sprintf("%-32s (%s)", appList.Applications[i].Metadata.Title(), appList.Applications[i].Name.String())
- }
-
sort.Strings(msg)
return msg
@@ -271,11 +271,10 @@ func (o *Options) listApplicationNames() tea.Msg {
// listScenarioNames returns a list of scenarios.
func (o *Options) listScenarioNames() tea.Msg {
ctx := context.TODO()
+ msg := internal.ScenarioMsg{}
// Isolate ULID from selection
parts := strings.Fields(o.generatorModel.ApplicationInput.Value())
- fmt.Println(o.generatorModel.ApplicationInput.Value())
- fmt.Println(parts)
appName := strings.Trim(parts[len(parts)-1], "()")
// Look up application to find url
@@ -284,17 +283,16 @@ func (o *Options) listScenarioNames() tea.Msg {
return err
}
- scenarioList, err := o.ApplicationsAPI.ListScenarios(ctx, app.Link(api.RelationScenarios), applications.ScenarioListQuery{})
+ l := applications.Lister{API: o.ApplicationsAPI}
+ q := applications.ScenarioListQuery{}
+ err = l.ForEachScenario(ctx, &app, q, func(item *applications.ScenarioItem) error {
+ msg = append(msg, fmt.Sprintf("%-32s (%s)", item.Title(), item.Name))
+ return nil
+ })
if err != nil {
return err
}
- msg := make(internal.ScenarioMsg, len(scenarioList.Scenarios))
-
- for i := range scenarioList.Scenarios {
- msg[i] = fmt.Sprintf("%-32s (%s)", scenarioList.Scenarios[i].Metadata.Title(), scenarioList.Scenarios[i].Name)
- }
-
sort.Strings(msg)
return msg
