mirror of
https://github.com/opbnq-q/nto-cli.git
synced 2025-12-07 00:00:34 +07:00
53 lines
915 B
Go
53 lines
915 B
Go
package cmd
|
|
|
|
import (
|
|
"log"
|
|
"nto_cli/utils"
|
|
"os"
|
|
|
|
"github.com/rivo/tview"
|
|
)
|
|
|
|
func SelectionInput() ([]string, string) {
|
|
if len(os.Args) == 1 {
|
|
log.Fatalf("Please provide path to models.go")
|
|
}
|
|
|
|
modelsPath := os.Args[1]
|
|
|
|
structNames := utils.GetNotImplementedStructs(modelsPath)
|
|
|
|
if len(structNames) == 0 {
|
|
log.Println("No unimplemented models -> nothing to do")
|
|
os.Exit(0)
|
|
}
|
|
|
|
var result []string
|
|
|
|
app := tview.NewApplication()
|
|
|
|
form := tview.NewForm()
|
|
var checkboxes []*tview.Checkbox
|
|
|
|
for _, name := range structNames {
|
|
cb := tview.NewCheckbox().SetLabel(name)
|
|
checkboxes = append(checkboxes, cb)
|
|
form.AddFormItem(cb)
|
|
}
|
|
|
|
form.AddButton("Generate", func() {
|
|
for i, cb := range checkboxes {
|
|
if cb.IsChecked() {
|
|
result = append(result, structNames[i])
|
|
}
|
|
}
|
|
app.Stop()
|
|
})
|
|
|
|
if err := app.SetRoot(form, true).Run(); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
return result, modelsPath
|
|
}
|