Add example for adding functions to cmd/scpt

This commit is contained in:
Elara 2021-03-02 00:33:55 -08:00
parent 1196942801
commit ba11fdcf76
2 changed files with 15 additions and 3 deletions

View File

@ -1,7 +1,9 @@
package main
import (
"errors"
"flag"
"fmt"
"gitea.arsenm.dev/Arsen6331/scpt"
"log"
"os"
@ -23,8 +25,20 @@ func main() {
if err != nil {
log.Fatalln("Error parsing file:", err)
}
scpt.AddFuncs(scpt.FuncMap{
"print": scptPrint,
})
err = ast.Execute()
if err != nil {
log.Fatalln("Error executing script:", err)
}
}
func scptPrint(args map[string]interface{}) (interface{}, error) {
val, ok := args[""]
if !ok {
return nil, errors.New("print requires an unnamed argument")
}
fmt.Println(val)
return nil, nil
}

View File

@ -14,8 +14,6 @@ if {3 == 3} {
}
}
do-shell-script "echo rpt"
repeat 5 times { z in
do-shell-script {"echo " + (string $z)}
print $z
}