61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
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)
|
|
}
|