/
vugugen.go
53 lines (40 loc) · 1.15 KB
/
vugugen.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
// vugugen is a command line tool to convert .vugu files into Go source code.
package main
import (
"flag"
"log"
"path/filepath"
"github.com/vugu/vugu/gen"
)
// we basically just wrap ParserGoPKg
func main() {
// vugugen path/to/package
var opts gen.ParserGoPkgOpts
flag.BoolVar(&opts.SkipGoMod, "skip-go-mod", false, "Do not try to create go.mod as needed")
flag.BoolVar(&opts.SkipMainGo, "skip-main", false, "Do not try to create main.go as needed")
flag.BoolVar(&opts.TinyGo, "tinygo", false, "Generate code intended for compilation under Tinygo")
flag.BoolVar(&opts.MergeSingle, "s", false, "Merge generated code for a package into a single file.")
recursive := flag.Bool("r", false, "Run recursively on specified path and subdirectories.")
flag.Parse()
args := flag.Args()
// default to current directory
if len(args) == 0 {
args = []string{"."}
}
for _, arg := range args {
pkgPath := arg
var err error
pkgPath, err = filepath.Abs(pkgPath)
if err != nil {
log.Fatal(err)
}
if *recursive {
err = gen.RunRecursive(pkgPath, &opts)
} else {
err = gen.Run(pkgPath, &opts)
}
if err != nil {
log.Fatal(err)
}
}
}