-
Notifications
You must be signed in to change notification settings - Fork 786
/
get_release.go
92 lines (82 loc) · 2.24 KB
/
get_release.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
package cmd
import (
"fmt"
"github.com/jenkins-x/jx/pkg/jx/cmd/templates"
"github.com/jenkins-x/jx/pkg/kube"
"github.com/jenkins-x/jx/pkg/log"
"github.com/jenkins-x/jx/pkg/util"
"github.com/spf13/cobra"
)
// GetReleaseOptions containers the CLI options
type GetReleaseOptions struct {
GetOptions
Filter string
Namespace string
}
var (
getReleaseLong = templates.LongDesc(`
Display one or more Releases
`)
getReleaseExample = templates.Examples(`
# List the recent releases done by this team
jx get release
# Filter the releases
jx get release -f myapp
`)
)
// NewCmdGetRelease creates the new command for: jx get env
func NewCmdGetRelease(commonOpts *CommonOptions) *cobra.Command {
options := &GetReleaseOptions{
GetOptions: GetOptions{
CommonOptions: commonOpts,
},
}
cmd := &cobra.Command{
Use: "releases",
Short: "Display the Release or Releases the current user is a member of",
Aliases: []string{"release"},
Long: getReleaseLong,
Example: getReleaseExample,
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
err := options.Run()
CheckErr(err)
},
}
cmd.Flags().StringVarP(&options.Filter, "filter", "f", "", "Filter the releases with the given text")
cmd.Flags().StringVarP(&options.Namespace, "namespace", "n", "", "The namespace to view or defaults to the current namespace")
options.addGetFlags(cmd)
return cmd
}
// Run implements this command
func (o *GetReleaseOptions) Run() error {
jxClient, curNs, err := o.JXClient()
if err != nil {
return err
}
ns := o.Namespace
if ns == "" {
ns = curNs
}
releases, err := kube.GetOrderedReleases(jxClient, ns, o.Filter)
if err != nil {
return err
}
if len(releases) == 0 {
suffix := ""
if o.Filter != "" {
suffix = fmt.Sprintf(" for filter: %s", util.ColorInfo(o.Filter))
}
log.Infof("No Releases found in namespace %s%s.\n", util.ColorInfo(ns), suffix)
log.Infof("To create a release try merging code to a master branch to trigger a pipeline or try: %s\n", util.ColorInfo("jx start build"))
return nil
}
table := o.createTable()
table.AddRow("NAME", "VERSION")
for _, release := range releases {
table.AddRow(release.Spec.Name, release.Spec.Version)
}
table.Render()
return nil
}