Skip to content

Commit 93bc717

Browse files
committed
apoxy proxies should list proxies
1 parent 332a1a0 commit 93bc717

File tree

1 file changed

+45
-37
lines changed

1 file changed

+45
-37
lines changed

cmd/proxy.go

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,6 @@ import (
1212
"github.com/apoxy-dev/apoxy-cli/pretty"
1313
)
1414

15-
// proxyCmd represents the proxy command
16-
var proxyCmd = &cobra.Command{
17-
Use: "proxy",
18-
Short: "Manage proxy objects",
19-
Long: `The core object in the Apoxy API.`,
20-
Aliases: []string{"p", "proxies"},
21-
Run: func(cmd *cobra.Command, args []string) {
22-
fmt.Println("proxy called")
23-
},
24-
}
25-
2615
func fmtProxy(r *v1alpha.Proxy) {
2716
t := pretty.Table{
2817
Header: buildProxyHeader(),
@@ -53,23 +42,57 @@ func buildProxyRow(r *v1alpha.Proxy) []interface{} {
5342
}
5443
}
5544

45+
func GetProxy(name string) error {
46+
c, err := defaultAPIClient()
47+
if err != nil {
48+
return err
49+
}
50+
r, err := c.Proxy().Get(name)
51+
if err != nil {
52+
return err
53+
}
54+
fmtProxy(r)
55+
return nil
56+
}
57+
58+
func ListProxies() error {
59+
c, err := defaultAPIClient()
60+
if err != nil {
61+
return err
62+
}
63+
r, err := c.Proxy().List()
64+
if err != nil {
65+
return err
66+
}
67+
t := pretty.Table{
68+
Header: buildProxyHeader(),
69+
}
70+
for _, p := range r.Items {
71+
t.Rows = append(t.Rows, buildProxyRow(&p))
72+
}
73+
t.Print()
74+
return nil
75+
}
76+
77+
// proxyCmd represents the proxy command
78+
var proxyCmd = &cobra.Command{
79+
Use: "proxy",
80+
Short: "Manage proxy objects",
81+
Long: `The core object in the Apoxy API.`,
82+
Aliases: []string{"p", "proxies"},
83+
RunE: func(cmd *cobra.Command, args []string) error {
84+
return ListProxies()
85+
},
86+
}
87+
5688
// getProxyCmd represents the get proxy command
5789
var getProxyCmd = &cobra.Command{
5890
Use: "get <name>",
5991
Short: "Get proxy objects",
6092
ValidArgs: []string{"name"},
6193
Args: cobra.ExactArgs(1),
6294
RunE: func(cmd *cobra.Command, args []string) error {
63-
c, err := defaultAPIClient()
64-
if err != nil {
65-
return err
66-
}
67-
r, err := c.Proxy().Get(args[0])
68-
if err != nil {
69-
return err
70-
}
71-
fmtProxy(r)
72-
return nil
95+
return GetProxy(args[0])
7396
},
7497
}
7598

@@ -78,22 +101,7 @@ var listProxyCmd = &cobra.Command{
78101
Use: "list",
79102
Short: "List proxy objects",
80103
RunE: func(cmd *cobra.Command, args []string) error {
81-
c, err := defaultAPIClient()
82-
if err != nil {
83-
return err
84-
}
85-
r, err := c.Proxy().List()
86-
if err != nil {
87-
return err
88-
}
89-
t := pretty.Table{
90-
Header: buildProxyHeader(),
91-
}
92-
for _, p := range r.Items {
93-
t.Rows = append(t.Rows, buildProxyRow(&p))
94-
}
95-
t.Print()
96-
return nil
104+
return ListProxies()
97105
},
98106
}
99107

0 commit comments

Comments
 (0)