Added help command

This commit is contained in:
Leon Mika 2024-12-11 21:16:08 +11:00
parent 5b4e45ff80
commit e0db900e4e
4 changed files with 120 additions and 28 deletions

View file

@ -2,6 +2,7 @@ package main
import (
"context"
"fmt"
"github.com/chzyer/readline"
"log"
"ucl.lmika.dev/repl"
@ -22,13 +23,24 @@ func main() {
)
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.
`,
})
for {
line, err := rl.Readline()
if err != nil { // io.EOF
break
}
if err := ucl.EvalAndDisplay(ctx, inst, line); err != nil {
if err := instRepl.EvalAndDisplay(ctx, line); err != nil {
log.Printf("%T: %v", err, err)
}
}