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.OS()), ucl.WithModule(builtins.FS(nil)), ucl.WithModule(builtins.Log(nil)), ucl.WithModule(builtins.Strs()), ) 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) } } }