forked from layerssss/freedom-routes
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
64 lines (53 loc) · 1.28 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"github.com/codegangsta/cli"
"github.com/sabersalv/freedom-routes/routes"
"os"
"path/filepath"
)
const VERSION = "1.1.0"
func genRoutes(templateNames []string, outputDir string) {
ips := routes.FetchIps()
if len(templateNames) == 1 {
os.MkdirAll(outputDir, 0755)
routes.Generate(templateNames[0], ips, outputDir)
} else {
for _, templateName := range templateNames {
output := filepath.Join(outputDir, templateName)
os.MkdirAll(output, 0755)
routes.Generate(templateName, ips, output)
}
}
}
func main() {
cli.AppHelpTemplate = `{{.Name}} v{{.Version}} - {{.Usage}}
USAGE:
{{.Name}} {{if .Flags}}[options] {{end}}<template ..>
COMMANDS:
{{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
{{end}}{{if .Flags}}
GLOBAL OPTIONS:
{{range .Flags}}{{.}}
{{end}}{{end}}
`
app := cli.NewApp()
app.Name = "freedom-routes"
app.Version = VERSION
app.Usage = "generate routes-up.sh and route-down.sh"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "output, o",
Value: ".",
Usage: "output directory",
},
}
app.Action = func(c *cli.Context) {
if c.Args().Present() {
genRoutes(c.Args(), c.String("output"))
} else {
cli.ShowAppHelp(c)
routes.PrintTemplatesPath()
}
}
app.Run(os.Args)
}