-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (56 loc) · 961 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"flag"
"fmt"
"os"
"strings"
)
var version string
func wout(f string, a ...any) {
fmt.Fprintf(os.Stdout, f+"\n", a...)
}
func werr(f string, a ...any) {
fmt.Fprintf(os.Stderr, f+"\n", a...)
}
func main() {
code := run(os.Args)
if code != 0 {
os.Exit(code)
}
}
func run(args []string) int {
var (
v = flag.Bool("v", false, "show version")
h = flag.Bool("h", false, "show help")
)
flag.Parse()
if *v {
showversion()
return 0
}
if *h {
showhelp()
return 0
}
env = &environment{modules: map[string]*module{}}
if len(args) <= 1 {
return repl()
}
a1 := args[1]
if !strings.HasSuffix(a1, ".sb") {
werr("%s must have .sb suffix", a1)
return 1
}
return interpret(a1)
}
func showversion() {
if version != "" {
fmt.Println(version)
return
}
fmt.Println("unknown version")
}
func showhelp() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
}