ucl/cmd/cmsh/main.go
Leon Mika e7f904e7da
All checks were successful
Build / build (push) Successful in 2m32s
Added some changes to call and added builtins
- call now supports calling invokables by string
- call now takes as arguments a listable of positional args, and a hashable of keyword args
- added strs:split, strs:join, and strs:has-prefix
- added new lists module with lists:first
- added time:sleep
2025-05-17 13:59:44 +10:00

59 lines
1.2 KiB
Go

package main
import (
"context"
"fmt"
"github.com/chzyer/readline"
"log"
"ucl.lmika.dev/repl"
"ucl.lmika.dev/ucl"
"ucl.lmika.dev/ucl/builtins"
)
func main() {
rl, err := readline.New("> ")
if err != nil {
panic(err)
}
defer rl.Close()
instRepl := repl.New(
ucl.WithModule(builtins.CSV(nil)),
ucl.WithModule(builtins.FS(nil)),
ucl.WithModule(builtins.Log(nil)),
ucl.WithModule(builtins.Itrs()),
ucl.WithModule(builtins.OS()),
ucl.WithModule(builtins.Strs()),
ucl.WithModule(builtins.Lists()),
ucl.WithModule(builtins.Time()),
)
ctx := context.Background()
instRepl.SetCommand("hello", func(ctx context.Context, args ucl.CallArgs) (any, error) {
fmt.Println("hello")
return nil, nil
}, repl.Doc{
Brief: "displays hello",
Detailed: `
This displays the message 'hello' to the terminal.
It then terminates.
`,
})
instRepl.SetCommand("new-fancy", newFancy, newFancyDoc)
instRepl.SetCommand("many-fancies", manyFancies)
repl.AddTypePrinter(instRepl, displayFancy)
repl.AddTypePrinter(instRepl, displayFancies)
for {
line, err := rl.Readline()
if err != nil { // io.EOF
break
}
if err := instRepl.EvalAndDisplay(ctx, line); err != nil {
log.Printf("%T: %v", err, err)
}
}
}