ucl/cmd/cmsh/main.go

35 lines
525 B
Go
Raw Permalink Normal View History

2024-04-10 10:45:58 +00:00
package main
import (
"context"
"github.com/chzyer/readline"
"log"
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-05-04 00:59:17 +00:00
inst := ucl.New(
ucl.WithModule(builtins.OS()),
ucl.WithModule(builtins.FS(nil)),
)
2024-04-10 10:45:58 +00:00
ctx := context.Background()
for {
line, err := rl.Readline()
if err != nil { // io.EOF
break
}
2024-04-27 00:11:22 +00:00
if err := ucl.EvalAndDisplay(ctx, inst, line); err != nil {
2024-04-10 10:45:58 +00:00
log.Printf("%T: %v", err, err)
}
}
}