Skip to content

Commit b5355d2

Browse files
Merge pull request #74 from ksctl/feature/new-region
feat: modularized the cardselection system
2 parents 7513910 + cdf9f4c commit b5355d2

13 files changed

Lines changed: 798 additions & 426 deletions

cmd/create.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ func (k *KsctlCommand) CostOptimizeAcrossRegion(inp chan CliRecommendation, meta
8484
return
8585
}
8686

87-
// k.PrintRecommendation(meta.ClusterType, optimizeResp)
88-
selectedReg, err := NewRegionRecommendation(meta.ClusterType, optimizeResp).Run()
87+
selectedReg, err := k.menuDriven.CardSelection(
88+
cli.ConverterForRecommendationIOutputForCards(optimizeResp, meta.ClusterType),
89+
)
8990
if err != nil {
9091
k.l.Error("Failed to get the recommendation options from user", "Reason", err)
9192
return

cmd/handle_meta.go

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,19 @@ func (k *KsctlCommand) handleRegionSelection(meta *controllerMeta.Controller, m
7676
ss.Stop()
7777

7878
k.l.Note(k.Ctx, "Carbon emission data shown represents monthly averages calculated over a one-year period")
79-
if v, ok := k.getSelectedRegion(listOfRegions); !ok {
79+
k.l.Note(k.Ctx, "Select the region for the cluster")
80+
81+
if v, err := k.menuDriven.CardSelection(
82+
cli.ConverterForRegionOutputForCards(listOfRegions),
83+
); err != nil {
84+
k.l.Error("Failed to get the region", "Reason", err)
8085
os.Exit(1)
8186
} else {
87+
if v == "" {
88+
k.l.Error("Region not selected")
89+
os.Exit(1)
90+
}
91+
k.l.Debug(k.Ctx, "Selected region", "Region", v)
8292
m.Region = v
8393
}
8494

@@ -121,17 +131,25 @@ func (k *KsctlCommand) handleInstanceTypeSelection(
121131
k.inMemInstanceTypesInReg = listOfVMs
122132
}
123133

124-
availableOptions := make(provider.InstancesRegionOutput, len(k.inMemInstanceTypesInReg))
134+
availableOptions := make(provider.InstancesRegionOutput, 0, len(k.inMemInstanceTypesInReg))
135+
136+
k.l.Note(k.Ctx, prompt)
125137

126138
for _, v := range k.inMemInstanceTypesInReg {
127-
if v.Category == category {
139+
if v.Category == category && v.CpuArch == provider.ArchAmd64 {
128140
availableOptions = append(availableOptions, v)
129141
}
130142
}
131143

132-
v, ok := k.getSelectedInstanceType(prompt, availableOptions)
133-
if !ok {
134-
k.l.Error("Failed to get the instance type")
144+
v, err := k.menuDriven.CardSelection(
145+
cli.ConverterForInstanceTypesForCards(availableOptions),
146+
)
147+
if err != nil {
148+
k.l.Error("Failed to get the instance type from user", "Reason", err)
149+
os.Exit(1)
150+
}
151+
if v == "" {
152+
k.l.Error("Instance type not selected")
135153
os.Exit(1)
136154
}
137155

0 commit comments

Comments
 (0)