Added help command
This commit is contained in:
parent
5b4e45ff80
commit
e0db900e4e
4 changed files with 120 additions and 28 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue