2024-04-10 10:45:58 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-12-11 10:16:08 +00:00
|
|
|
"fmt"
|
2024-04-10 10:45:58 +00:00
|
|
|
"github.com/chzyer/readline"
|
|
|
|
"log"
|
2024-12-11 09:47:05 +00:00
|
|
|
"ucl.lmika.dev/repl"
|
2024-04-27 01:00:48 +00:00
|
|
|
"ucl.lmika.dev/ucl"
|
2024-05-04 00:59:17 +00:00
|
|
|
"ucl.lmika.dev/ucl/builtins"
|
2024-04-10 10:45:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
rl, err := readline.New("> ")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer rl.Close()
|
|
|
|
|
2024-12-11 09:47:05 +00:00
|
|
|
instRepl := repl.New(
|
2024-05-04 00:59:17 +00:00
|
|
|
ucl.WithModule(builtins.OS()),
|
|
|
|
ucl.WithModule(builtins.FS(nil)),
|
|
|
|
)
|
2024-04-10 10:45:58 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
|
2024-12-11 10:16:08 +00:00
|
|
|
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.
|
|
|
|
`,
|
|
|
|
})
|
|
|
|
|
2024-04-10 10:45:58 +00:00
|
|
|
for {
|
|
|
|
line, err := rl.Readline()
|
|
|
|
if err != nil { // io.EOF
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2024-12-11 10:16:08 +00:00
|
|
|
if err := instRepl.EvalAndDisplay(ctx, line); err != nil {
|
2024-04-10 10:45:58 +00:00
|
|
|
log.Printf("%T: %v", err, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|