-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
55 lines (42 loc) · 1005 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
package main
import (
"flag"
"fmt"
"os"
"github.com/boourns/scaffold/ast"
"github.com/boourns/scaffold/model"
"github.com/boourns/scaffold/static"
)
var flags *flag.FlagSet
var scaffolds = map[string]ast.Scaffold{
"model": model.Scaffold,
"static": static.Scaffold,
}
func init() {
flags = flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
}
func main() {
if len(os.Args) < 2 {
fmt.Println("Scaffold missing. Usage:", os.Args[0], "<scaffold name>")
printValidScaffolds()
flags.PrintDefaults()
return
}
scaffoldName := os.Args[1]
scaffold, ok := scaffolds[scaffoldName]
if !ok {
fmt.Printf("Invalid scaffold: %s", scaffoldName)
printValidScaffolds()
}
fmt.Printf("- Running %s\n", scaffoldName)
err := scaffold.Generate(flags)
if err != nil {
fmt.Printf("Error generating %s: %s\n", scaffoldName, err)
}
}
func printValidScaffolds() {
fmt.Println("Valid scaffolds are:")
for name, s := range scaffolds {
fmt.Printf("%s: %s\n", name, s.Description())
}
}