-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
107 lines (95 loc) · 2.11 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
import (
"fmt"
"github.com/andy-zhangtao/systemd-service-make/gpl"
"github.com/andy-zhangtao/systemd-service-make/module"
"github.com/andy-zhangtao/systemd-service-make/tools"
"github.com/urfave/cli"
"log"
"os"
"sort"
"strings"
)
var name string
var desc string
var after string
var requires string
var image string
var raw string
func main() {
app := cli.NewApp()
app.Name = "Service Maker"
app.Usage = "Generate Systemd Service"
app.Version = "0.1.0"
app.Author = "ztao8607@gmail.com"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "name, n",
Usage: "Service Name. Require",
Destination: &name,
},
cli.StringFlag{
Name: "desc, d",
Usage: "Service Desc",
Destination: &desc,
},
cli.StringFlag{
Name: "After, af",
Usage: "The After Service List. Multiple service use ',' for split",
Destination: &after,
},
cli.StringFlag{
Name: "Requires, r",
Usage: "The Require Services. Multiple service use ',' for split",
Destination: &requires,
},
cli.StringSliceFlag{
Name: "Args,ar",
Usage: "The Docker run args",
},
cli.StringFlag{
Name: "Image, i",
Usage: "The Image Name. Require",
Destination: &image,
},
cli.StringFlag{
Name: "Raw, raw",
Usage: "The raw docker run command",
Destination: &raw,
},
}
app.Action = func(c *cli.Context) error {
if !check() {
fmt.Println("Name and Image are mandatory choose. PLease see smarker usage")
cli.ShowAppHelpAndExit(c, -1)
}
service := module.SystemdServiceModule{
Name: name,
Desc: desc,
AfterService: strings.Split(after, ","),
Requires: requires,
Image: image,
}
if raw != "" {
service.Args = tools.ParseRawArgs(raw)
}
if len(c.StringSlice("ar")) > 0 {
service.Args = c.StringSlice("ar")
}
return gpl.GenerateSystemdService(service)
}
sort.Sort(cli.FlagsByName(app.Flags))
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}
func check() bool {
if name == "" {
return false
}
if image == "" {
return false
}
return true
}