-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_url.go
95 lines (81 loc) · 1.95 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
88
89
90
91
92
93
94
95
package cmd
import (
"io"
"github.com/spf13/cobra"
"gopkg.in/AlecAivazis/survey.v1/terminal"
"github.com/jenkins-x/jx/pkg/jx/cmd/templates"
"github.com/jenkins-x/jx/pkg/kube"
)
// 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(f Factory, in terminal.FileReader, out terminal.FileWriter, errOut io.Writer) *cobra.Command {
options := &GetURLOptions{
GetOptions: GetOptions{
CommonOptions: CommonOptions{
Factory: f,
In: in,
Out: out,
Err: errOut,
},
},
}
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.KubeClient()
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 := kube.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
}