Skip to content

Commit

Permalink
Use huh for selecting db on connect
Browse files Browse the repository at this point in the history
  • Loading branch information
lewissteele committed Nov 27, 2024
1 parent e3af2e1 commit 143a17a
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions cmd/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"image/color"

"github.com/c-bata/go-prompt"
"github.com/charmbracelet/huh"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/lewissteele/dbat/internal/db"
"github.com/lewissteele/dbat/internal/input"
"github.com/manifoldco/promptui"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -100,13 +100,27 @@ func selectedDB(args []string) string {
return args[0]
}

prompt := promptui.Select{
HideHelp: true,
Items: db.UserDBNames(),
Label: "database",
var name string

options := []huh.Option[string]{}

for _, n := range db.UserDBNames() {
options = append(options, huh.NewOption[string](n, n))
}

_, name, _ := prompt.Run()
form := huh.NewForm(
huh.NewGroup(
huh.NewSelect[string]().Title("database").Value(&name).Options(
options...
),
),
)

err := form.Run()

if err != nil {
panic(err)
}

return name
}

0 comments on commit 143a17a

Please sign in to comment.