-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
releasing.go
87 lines (72 loc) · 1.63 KB
/
releasing.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
package main
import (
"fmt"
"log"
"github.com/spf13/cobra"
)
var modules = [...]string{
"kyaml", "api", "kstatus", "cmd/config",
"cmd/resource", "cmd/kubectl", "pluginator", "kustomize",
}
var verbose bool
// === Log helper functions ===
func logDebug(s string) {
if verbose {
log.Println("DEBUG " + s)
}
}
func logInfo(s string) {
log.Println("INFO " + s)
}
func logFatal(s string) {
log.Fatalln("FATAL " + s)
}
var rootCmd = &cobra.Command{
Use: "releasing",
Short: "This go program is used to improve the modules releasing process in Kustomize repository.",
}
var listSubCmd = &cobra.Command{
Use: "list",
Short: "List current version of all covered modules",
Run: func(cmd *cobra.Command, args []string) {
res := []string{}
for _, mod := range modules {
res = append(res, fmt.Sprintf("%s/%s", mod, getModuleCurrentVersion(mod)))
}
for _, l := range res {
fmt.Println(l)
}
},
}
var subCmds = [...]*cobra.Command{
listSubCmd,
}
func main() {
for _, cmd := range subCmds {
rootCmd.AddCommand(cmd)
}
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose output")
if err := rootCmd.Execute(); err != nil {
logFatal(err.Error())
}
}
func getModuleCurrentVersion(modName string) string {
mod := newModule(modName)
mod.updateCurrentVersion()
return mod.currentVersion
}
type module struct {
name string
path string
currentVersion string
}
func newModule(modName string) module {
mod := module{
name: modName,
}
logDebug(fmt.Sprintf("Created module struct for %s", modName))
return mod
}
func (m *module) updateCurrentVersion() {
m.currentVersion = "v1.0.0"
}