forked from layerssss/freedom-routes
-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.go
54 lines (45 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
51
52
53
54
package main
import (
"github.com/SaberSalv/freedom-routes/routes"
"fmt"
"github.com/ogier/pflag"
"path/filepath"
"os"
)
const VERSION = "1.1.0"
var USAGE = `
$ freedom-routes [options] <template ..>
OPTIONS:
-o, --output="." # output directory
-h, --help
--version
`
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() {
pflag.Usage = func() {
fmt.Fprintf(os.Stderr, USAGE)
}
var output = pflag.StringP("output", "o", ".", "output directory")
var version = pflag.BoolP("version", "", false, "version")
pflag.Parse()
if *version {
fmt.Println(VERSION)
} else if pflag.NArg() > 0 {
genRoutes(pflag.Args(), *output)
} else {
routes.PrintTemplatesPath()
pflag.Usage()
}
}