-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (43 loc) · 1.05 KB
/
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
package main
import "fmt"
import "os"
import "flag"
import "goast"
import "goir/gen"
var exitcodes = map[string]int{
"ok": 0,
"usage": 1,
"badpath": 2,
"barf": 3,
}
func usage(status int) {
fmt.Fprint(os.Stderr, `dummy program`)
os.Exit(status)
}
func error(s string) {
fmt.Fprintln(os.Stderr, s)
}
func main() {
ext := flag.String("ext", ".go", "The extension of the files to parse.")
pack := flag.String("pack", "", "The package you want the AST of.")
flag.Parse()
args := flag.Args()
if *pack == "" {
error("A package name is required.")
usage(exitcodes["usage"])
}
if len(args) < 1 {
error("A path to a go file is required.")
usage(exitcodes["usage"])
} else if len(args) > 1 {
error("To many arguments, only one file is allowed.")
usage(exitcodes["usage"])
}
path := args[0]
ast, err := goast.ParsePackage(path, *ext, *pack)
if err != nil {
error(err.String())
usage(exitcodes["usage"])
}
gen.Generate(ast)
}