-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaspartame.go
63 lines (51 loc) · 1.1 KB
/
aspartame.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
package main
import (
"flag"
"fmt"
"log"
"strings"
"github.com/falun/aspartame/generators"
)
func outputPath(outputArg string) *string {
var s = new(string)
switch outputArg {
case "stdout":
return nil
case "file":
*s = ""
default:
parts := strings.Split(outputArg, ":")
if len(parts) != 2 || parts[0] != "file" {
log.Fatal("Invalid -dest target:", outputArg)
}
*s = parts[1]
}
return s
}
func main() {
var (
target string
filePath string
output string
)
flag.StringVar(&target, "type", "enum", "What kind of sweetening should we be doing")
flag.StringVar(&filePath, "source", "./", "File, or directory, to operate on")
flag.StringVar(&output, "dest", "file", "Where should we produce output (file[:name]|stdout)")
for _, e := range generators.All() {
e.SetupFlags()
}
flag.Parse()
if filePath == "" {
fmt.Println("-source must be specified")
return
}
g, gErr := generators.Find(target)
if gErr != nil {
log.Fatal(gErr)
}
f := g.LocateFile(filePath)
if f == nil {
log.Fatal("Could not find a file to operate on.")
}
g.DoGenerate(f, outputPath(output))
}