-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
119 lines (112 loc) · 2.88 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
108
109
110
111
112
113
114
115
116
117
118
119
package main
import (
"github.com/codegangsta/cli"
"os"
)
func main() {
app := cli.NewApp()
app.Name = "kube"
app.Usage = "cli for sharing kubernetes resource files repos and management"
app.Version = "1.0.2"
// global level flags
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "verbose",
Usage: "Show more output",
},
}
app.Commands = []cli.Command{
{
Name: "search",
Aliases: []string{"s"},
Usage: "Search global kubernetes resource with keyword.",
Action: func(c *cli.Context) {
keyword := ""
if len(c.Args()) > 1 {
println("NOTICE: Only support one keyword in v1")
}
if len(c.Args()) > 0 {
keyword = c.Args()[0]
searchTag(keyword)
} else {
println("you need at least one keyword for search. for example: kube search redis")
}
},
},
{
Name: "push",
Usage: "Push resource files to kube.hub with tag",
Flags: []cli.Flag{
cli.StringFlag{
Name: "tag, t",
Usage: "Tag your kubernetes resource files repo a name.",
},
cli.StringFlag{
Name: "description, d",
Usage: "Write a description for your kubernetes resource repo.",
},
},
Action: func(c *cli.Context) {
filename := ""
tag := ""
description := ""
if len(c.Args()) > 1 {
println("NOTICE: Only pushing one resource file in v1")
}
if len(c.Args()) > 0 {
if c.String("tag") == "" {
println("You need to specify a tag")
return
}
filename = c.Args()[0]
tag = c.String("tag")
description = c.String("description")
println("pushing file: ", filename)
println("with tag: ", tag)
println("with description: ", description)
pushFile(filename, tag, description)
} else {
println("You need to push with files, for example: kube push my-redis-rc.json -t ming.redis")
}
},
},
{
Name: "pull",
Usage: "Get resource files from kube.hub by tag",
Action: func(c *cli.Context) {
tag := ""
if len(c.Args()) > 1 {
println("NOTICE: Only get one repo at a time")
}
if len(c.Args()) > 0 {
tag = c.Args().First()
println("get tag: ", tag)
println("HELP: You can run kubectl create -f <the yaml or json file>")
getFile(tag)
} else {
println("NOTICE: You need to specify a tag for download, for example: kube pull ming.redis")
println("NOTICE: You can use subcommand search to find one, for example: kube search redis.")
}
},
},
{
Name: "like",
Aliases: []string{"star"},
Usage: "Add a star for a specific resource tag",
Action: func(c *cli.Context) {
tag := ""
if len(c.Args()) > 1 {
println("NOTICE: Only like one repo at a time")
}
if len(c.Args()) > 0 {
tag = c.Args().First()
println("I like tag: ", tag)
likeIt(tag)
} else {
println("NOTICE: You need to specify a tag to give it a start")
}
},
},
}
app.Run(os.Args)
}