Add example for adding functions to cmd/scpt
This commit is contained in:
parent
1196942801
commit
ba11fdcf76
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user