-
Notifications
You must be signed in to change notification settings - Fork 12
/
commands.go
82 lines (70 loc) · 1.63 KB
/
commands.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"log"
"os"
"fmt"
"github.com/codegangsta/cli"
"github.com/mono0926/ios-license-generator/generator"
"github.com/mono0926/ios-license-generator/io"
"github.com/mono0926/ios-license-generator/parser"
"io/ioutil"
)
var Commands = []cli.Command{
commandGenerate,
}
var commandGenerate = cli.Command{
Name: "generate",
Usage: "",
Description: `
`,
Action: doGenerate,
}
func debug(v ...interface{}) {
if os.Getenv("DEBUG") != "" {
log.Println(v...)
}
}
func assert(err error) {
if err != nil {
log.Fatal(err)
}
}
func doGenerate(c *cli.Context) {
args := c.Args()
if len(args) != 2 {
log.Println("Specify license path and output path!")
return
}
path := args[0]
outDir := args[1]
if err := os.MkdirAll(outDir, 0777); err != nil {
log.Println("cant create output dir")
return
}
lines, e := reader.ReadLines(path)
if e != nil {
log.Println("invalid license file")
return
}
names := make([]string, 1)
for _, l := range lines {
match, name, body := parser.Fetch(l)
if !match {
log.Println("invalid license line")
continue
}
licenseData, e := Asset("template/License.plist")
assert(e)
s := generator.GenerateLicense(string(licenseData), name, body)
log.Println(s)
ioutil.WriteFile(fmt.Sprintf("%s/%s.plist", outDir, name), []byte(s), 0644)
names = append(names, name)
}
listData, e := Asset("template/LicenseList.plist")
assert(e)
itemData, e := Asset("template/LicenseListItem.plist")
assert(e)
s := generator.GenerateLicenseList(string(listData), string(itemData), names)
log.Println(s)
ioutil.WriteFile(fmt.Sprintf("%s/LicenseList.plist", outDir), []byte(s), 0644)
}