fix: paths, feat: many models, selection

This commit is contained in:
2025-03-06 23:51:54 +07:00
parent 63360da52e
commit 77ff582d59
8 changed files with 192 additions and 32 deletions

View File

@@ -1,10 +1,50 @@
package input
package cmd
import "fmt"
import (
"fmt"
"nto_cli/utils"
"os"
"github.com/rivo/tview"
)
func Input() (string, string) {
fmt.Print("struct name, path to file (including struct): ")
var structName, path string
fmt.Scan(&structName, &path)
return structName, path
}
}
func SelectionInput() ([]string, string) {
path := os.Args[1]
structNames := utils.GetStructList(path)
result := []string{}
app := tview.NewApplication()
form := tview.NewForm()
checkboxes := []*tview.Checkbox{}
for _, name := range structNames {
cb := tview.NewCheckbox().SetLabel(name)
checkboxes = append(checkboxes, cb)
form.AddFormItem(cb)
}
form.AddButton("Confirm", 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, path
}