forked from jenkins-x/jx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_quickstart_locations.go
105 lines (87 loc) · 2.51 KB
/
get_quickstart_locations.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
package cmd
import (
"io"
"strings"
"github.com/jenkins-x/jx/pkg/gits"
"github.com/jenkins-x/jx/pkg/jx/cmd/templates"
"github.com/jenkins-x/jx/pkg/kube"
"github.com/spf13/cobra"
"gopkg.in/AlecAivazis/survey.v1/terminal"
)
// GetQuickstartLocationOptions containers the CLI options
type GetQuickstartLocationOptions struct {
GetOptions
}
const (
quickstartLocation = "quickstartlocation"
quickstartLocations = quickstartLocation + "s"
)
var (
quickstartLocationsAliases = []string{
quickstartLocation, "quickstartloc", "qsloc",
}
getQuickstartLocationLong = templates.LongDesc(`
Display one or more Quickstart Locations for the current Team.
For more documentation see: [https://jenkins-x.io/developing/create-quickstart/#customising-your-teams-quickstarts](https://jenkins-x.io/developing/create-quickstart/#customising-your-teams-quickstarts)
`)
getQuickstartLocationExample = templates.Examples(`
# List all the quickstart locations
jx get quickstartlocations
# List all the quickstart locations via an alias
jx get qsloc
`)
)
// NewCmdGetQuickstartLocation creates the new command for: jx get env
func NewCmdGetQuickstartLocation(f Factory, in terminal.FileReader, out terminal.FileWriter, errOut io.Writer) *cobra.Command {
options := &GetQuickstartLocationOptions{
GetOptions: GetOptions{
CommonOptions: CommonOptions{
Factory: f,
In: in,
Out: out,
Err: errOut,
},
},
}
cmd := &cobra.Command{
Use: quickstartLocations,
Short: "Display one or more Quickstart Locations",
Aliases: quickstartLocationsAliases,
Long: getQuickstartLocationLong,
Example: getQuickstartLocationExample,
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
err := options.Run()
CheckErr(err)
},
}
options.addGetFlags(cmd)
return cmd
}
// Run implements this command
func (o *GetQuickstartLocationOptions) Run() error {
jxClient, ns, err := o.JXClientAndDevNamespace()
if err != nil {
return err
}
err = o.registerEnvironmentCRD()
if err != nil {
return err
}
locations, err := kube.GetQuickstartLocations(jxClient, ns)
if err != nil {
return err
}
table := o.CreateTable()
table.AddRow("GIT SERVER", "KIND", "OWNER", "INCLUDES", "EXCLUDES")
for _, location := range locations {
kind := location.GitKind
if kind == "" {
kind = gits.KindGitHub
}
table.AddRow(location.GitURL, kind, location.Owner, strings.Join(location.Includes, ", "), strings.Join(location.Excludes, ", "))
}
table.Render()
return nil
}