|
8 | 8 | "strings" |
9 | 9 | "time" |
10 | 10 |
|
11 | | - "github.com/AlecAivazis/survey/v2" |
12 | 11 | "github.com/briandowns/spinner" |
| 12 | + "github.com/charmbracelet/huh" |
13 | 13 | "github.com/charmbracelet/lipgloss" |
14 | 14 | "github.com/hostodo/hostodo-cli/pkg/api" |
15 | 15 | "github.com/hostodo/hostodo-cli/pkg/auth" |
@@ -220,12 +220,13 @@ func selectTemplate(templates []api.Template, flag string, jsonMode bool) (*api. |
220 | 220 | osOptions[i] = t.Name |
221 | 221 | } |
222 | 222 | var selected string |
223 | | - prompt := &survey.Select{ |
224 | | - Message: "Choose an OS:", |
225 | | - Options: osOptions, |
226 | | - PageSize: 15, |
227 | | - } |
228 | | - if err := survey.AskOne(prompt, &selected); err != nil { |
| 223 | + err := huh.NewSelect[string](). |
| 224 | + Title("Choose an OS:"). |
| 225 | + Options(huh.NewOptions(osOptions...)...). |
| 226 | + Value(&selected). |
| 227 | + Height(15). |
| 228 | + Run() |
| 229 | + if err != nil { |
229 | 230 | return nil, err |
230 | 231 | } |
231 | 232 | tmpl, _ := findTemplate(templates, selected) |
@@ -255,12 +256,13 @@ func selectRegion(regions []api.Region, flag string, jsonMode bool) (*api.Region |
255 | 256 | regionOptions[i] = r.Name |
256 | 257 | } |
257 | 258 | var selected string |
258 | | - prompt := &survey.Select{ |
259 | | - Message: "Choose a region:", |
260 | | - Options: regionOptions, |
261 | | - PageSize: 15, |
262 | | - } |
263 | | - if err := survey.AskOne(prompt, &selected); err != nil { |
| 259 | + err := huh.NewSelect[string](). |
| 260 | + Title("Choose a region:"). |
| 261 | + Options(huh.NewOptions(regionOptions...)...). |
| 262 | + Value(&selected). |
| 263 | + Height(15). |
| 264 | + Run() |
| 265 | + if err != nil { |
264 | 266 | return nil, err |
265 | 267 | } |
266 | 268 | region, _ := findRegion(regions, selected) |
@@ -293,12 +295,13 @@ func selectPlan(plans []api.Plan, flag string, jsonMode bool, billingCycle strin |
293 | 295 | p.Name, price, suffix, p.VCPU, formatRAM(p.RAM), p.Disk, formatBW(p.Bandwidth)) |
294 | 296 | } |
295 | 297 | var selected string |
296 | | - prompt := &survey.Select{ |
297 | | - Message: "Choose a plan:", |
298 | | - Options: planOptions, |
299 | | - PageSize: 15, |
300 | | - } |
301 | | - if err := survey.AskOne(prompt, &selected); err != nil { |
| 298 | + err := huh.NewSelect[string](). |
| 299 | + Title("Choose a plan:"). |
| 300 | + Options(huh.NewOptions(planOptions...)...). |
| 301 | + Value(&selected). |
| 302 | + Height(15). |
| 303 | + Run() |
| 304 | + if err != nil { |
302 | 305 | return nil, err |
303 | 306 | } |
304 | 307 | planName := strings.Fields(selected)[0] |
@@ -347,12 +350,13 @@ func selectSSHKey(client *api.Client, flag string, jsonMode bool) (string, error |
347 | 350 | keyOptions[i] = fmt.Sprintf("%s (%s)", key.Name, fingerprint) |
348 | 351 | } |
349 | 352 | var selected string |
350 | | - prompt := &survey.Select{ |
351 | | - Message: "Choose an SSH key:", |
352 | | - Options: keyOptions, |
353 | | - PageSize: 10, |
354 | | - } |
355 | | - if err := survey.AskOne(prompt, &selected); err != nil { |
| 353 | + err = huh.NewSelect[string](). |
| 354 | + Title("Choose an SSH key:"). |
| 355 | + Options(huh.NewOptions(keyOptions...)...). |
| 356 | + Value(&selected). |
| 357 | + Height(10). |
| 358 | + Run() |
| 359 | + if err != nil { |
356 | 360 | return "", err |
357 | 361 | } |
358 | 362 | return strings.Split(selected, " (")[0], nil |
@@ -387,12 +391,12 @@ func confirmDeploy(tmpl *api.Template, region *api.Region, plan *api.Plan, hostn |
387 | 391 |
|
388 | 392 | confirmMsg := fmt.Sprintf("Deploy? (charges $%s to %s ****%s)", |
389 | 393 | quote.AmountDue, pm.CardType, pm.LastFour) |
390 | | - var confirmed bool |
391 | | - prompt := &survey.Confirm{ |
392 | | - Message: confirmMsg, |
393 | | - Default: true, |
394 | | - } |
395 | | - if err := survey.AskOne(prompt, &confirmed); err != nil { |
| 394 | + confirmed := true |
| 395 | + err := huh.NewConfirm(). |
| 396 | + Title(confirmMsg). |
| 397 | + Value(&confirmed). |
| 398 | + Run() |
| 399 | + if err != nil { |
396 | 400 | return false, err |
397 | 401 | } |
398 | 402 | return confirmed, nil |
@@ -517,12 +521,12 @@ SSH: ssh %s@%s`, |
517 | 521 | } |
518 | 522 |
|
519 | 523 | func promptSSHConnect(hostname string) { |
520 | | - var connectNow bool |
521 | | - prompt := &survey.Confirm{ |
522 | | - Message: "Connect now?", |
523 | | - Default: true, |
524 | | - } |
525 | | - if err := survey.AskOne(prompt, &connectNow); err != nil { |
| 524 | + connectNow := true |
| 525 | + err := huh.NewConfirm(). |
| 526 | + Title("Connect now?"). |
| 527 | + Value(&connectNow). |
| 528 | + Run() |
| 529 | + if err != nil { |
526 | 530 | return |
527 | 531 | } |
528 | 532 | if connectNow { |
@@ -822,12 +826,13 @@ func selectBillingCycle(plans []api.Plan, flag string, jsonMode bool) (string, e |
822 | 826 | options[i] = billingCycleLabel(c) |
823 | 827 | } |
824 | 828 | var selected string |
825 | | - prompt := &survey.Select{ |
826 | | - Message: "Choose a billing cycle:", |
827 | | - Options: options, |
828 | | - PageSize: 10, |
829 | | - } |
830 | | - if err := survey.AskOne(prompt, &selected); err != nil { |
| 829 | + err := huh.NewSelect[string](). |
| 830 | + Title("Choose a billing cycle:"). |
| 831 | + Options(huh.NewOptions(options...)...). |
| 832 | + Value(&selected). |
| 833 | + Height(10). |
| 834 | + Run() |
| 835 | + if err != nil { |
831 | 836 | return "", err |
832 | 837 | } |
833 | 838 | for _, c := range availableCycles { |
|
0 commit comments