Skip to content

Commit

Permalink
Move shared logic into separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
lewissteele committed Nov 27, 2024
1 parent deacf04 commit b03fec8
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions cmd/shared.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cmd

import (
"errors"

"github.com/charmbracelet/huh"
"github.com/lewissteele/dbat/internal/db"
)

func isNotBlank(val string) error {

Check failure on line 10 in cmd/shared.go

View workflow job for this annotation

GitHub Actions / build

isNotBlank redeclared in this block
if len(val) > 0 {
return nil
}

return errors.New("value cannot be blank")
}

func selectedDB(args []string) string {

Check failure on line 18 in cmd/shared.go

View workflow job for this annotation

GitHub Actions / build

selectedDB redeclared in this block
if len(args) > 0 {
return args[0]
}

var name string

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

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

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 b03fec8

Please sign in to comment.