Started re-engineering the UCL command instance

This commit is contained in:
Leon Mika 2025-05-15 22:16:02 +10:00
parent 94b58e2168
commit 17381f3d0b
9 changed files with 309 additions and 172 deletions

View file

@ -0,0 +1,60 @@
package cmdpacks
import (
"context"
tea "github.com/charmbracelet/bubbletea"
"github.com/lmika/dynamo-browse/internal/common/ui/commandctrl"
"github.com/lmika/dynamo-browse/internal/dynamo-browse/controllers"
"ucl.lmika.dev/repl"
"ucl.lmika.dev/ucl"
)
type StandardCommands struct {
ReadController *controllers.TableReadController
}
var cmdQuitDoc = repl.Doc{
Brief: "Quits dynamo-browse",
Usage: "quit",
Detailed: `
This will quit dynamo-browse immediately, without prompting to apply
any changes.
`,
}
func (sc StandardCommands) cmdQuit(ctx context.Context, args ucl.CallArgs) (any, error) {
commandctrl.PostMsg(ctx, tea.Quit)
return nil, nil
}
var cmdTableDoc = repl.Doc{
Brief: "Prompt for table to scan",
Usage: "table [NAME]",
Args: []repl.ArgDoc{
{Name: "name", Brief: "Name of the table to scan"},
},
Detailed: `
If called with an argument, it will scan the table with that name and
replace the current result set. If called without an argument, it will
prompt for a table to scan.
This command is intended only for interactive sessions and is not suitable
for scripting. The scan or table prompts will happen asynchronously.
`,
}
func (sc StandardCommands) cmdTable(ctx context.Context, args ucl.CallArgs) (any, error) {
var tableName string
if err := args.Bind(&tableName); err == nil {
commandctrl.PostMsg(ctx, sc.ReadController.ScanTable(tableName))
return nil, nil
}
commandctrl.PostMsg(ctx, sc.ReadController.ListTables(false))
return nil, nil
}
func (sc StandardCommands) ConfigureUCL(ucl *ucl.Inst) {
ucl.SetBuiltin("quit", sc.cmdQuit)
ucl.SetBuiltin("table", sc.cmdTable)
}