-
Notifications
You must be signed in to change notification settings - Fork 787
/
get_url.go
87 lines (74 loc) · 1.8 KB
/
get_url.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 cmd
import (
"github.com/jenkins-x/jx/pkg/kube/services"
"github.com/spf13/cobra"
"github.com/jenkins-x/jx/pkg/jx/cmd/templates"
)
// GetURLOptions the command line options
type GetURLOptions struct {
GetOptions
Namespace string
Environment string
}
var (
get_url_long = templates.LongDesc(`
Display one or more URLs from the running services.
`)
get_url_example = templates.Examples(`
# List all URLs in this namespace
jx get url
`)
)
// NewCmdGetURL creates the command
func NewCmdGetURL(commonOpts *CommonOptions) *cobra.Command {
options := &GetURLOptions{
GetOptions: GetOptions{
CommonOptions: commonOpts,
},
}
cmd := &cobra.Command{
Use: "urls [flags]",
Short: "Display one or more URLs",
Long: get_url_long,
Example: get_url_example,
Aliases: []string{"url"},
Run: func(cmd *cobra.Command, args []string) {
options.Cmd = cmd
options.Args = args
err := options.Run()
CheckErr(err)
},
}
options.addGetUrlFlags(cmd)
return cmd
}
func (o *GetURLOptions) addGetUrlFlags(cmd *cobra.Command) {
cmd.Flags().StringVarP(&o.Namespace, "namespace", "n", "", "Specifies the namespace name to look inside")
cmd.Flags().StringVarP(&o.Environment, "env", "e", "", "Specifies the Environment name to look inside")
}
// Run implements this command
func (o *GetURLOptions) Run() error {
client, ns, err := o.KubeClientAndNamespace()
if err != nil {
return err
}
if o.Namespace != "" {
ns = o.Namespace
} else if o.Environment != "" {
ns, err = o.findEnvironmentNamespace(o.Environment)
if err != nil {
return err
}
}
urls, err := services.FindServiceURLs(client, ns)
if err != nil {
return err
}
table := o.createTable()
table.AddRow("Name", "URL")
for _, url := range urls {
table.AddRow(url.Name, url.URL)
}
table.Render()
return nil
}