forked from robertkrimen/otto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (38 loc) · 806 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"github.com/couchbaselabs/otto"
"github.com/couchbaselabs/otto/underscore"
)
var underscoreFlag *bool = flag.Bool("underscore", true, "Load underscore into the runtime environment")
func main() {
flag.Parse()
var script []byte
var err error
filename := flag.Arg(0)
if filename == "" || filename == "-" {
script, err = ioutil.ReadAll(os.Stdin)
if err != nil {
fmt.Printf("Can't read stdin: %v\n", err)
os.Exit(64)
}
} else {
script, err = ioutil.ReadFile(filename)
if err != nil {
fmt.Printf("Can't open file \"%v\": %v\n", filename, err)
os.Exit(64)
}
}
if !*underscoreFlag {
underscore.Disable()
}
Otto := otto.New()
_, err = Otto.Run(string(script))
if err != nil {
fmt.Println(err)
os.Exit(64)
}
}