Skip to content

Commit 8e8aee4

Browse files
author
Mehrad
committed
update the portforward command
1 parent d160ed7 commit 8e8aee4

2 files changed

Lines changed: 72 additions & 71 deletions

File tree

cmd/command_open_portforward.go

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,15 @@ import (
44
"github.com/spf13/cobra"
55
)
66

7-
// Open Command
87
var (
98
openCmd = &cobra.Command{
109
Use: "open [Application.name]",
1110
Short: "Open an Application in the default browser",
1211
Long: `This subcommand will open an application in the default browser in every os.`,
1312
Run: appOpen}
14-
)
1513

16-
// Portforward Command
17-
var (
1814
portforwardCmd = &cobra.Command{
19-
Use: "portforward [command] [name]",
20-
Short: "portforward to connect to an application running in a cluster",
21-
Long: `Portforward to connect to an application running in a cluster.
22-
This type of connection can be useful for database debugging`,
23-
Run: func(cmd *cobra.Command, args []string) {
24-
cmd.Help()
25-
}}
26-
27-
portforwardSrvCmd = &cobra.Command{
28-
Use: "service [name]",
15+
Use: "portforward [srvice.name]",
2916
Short: "portforward to connect to an application running in a cluster",
3017
Long: `Portforward to connect to an application running in a cluster.
3118
This type of connection can be useful for database debugging`,
@@ -36,7 +23,4 @@ func init() {
3623
rootCmd.AddCommand(
3724
portforwardCmd,
3825
openCmd)
39-
40-
portforwardCmd.AddCommand(
41-
portforwardSrvCmd)
4226
}

cmd/ui.go

Lines changed: 71 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212
"strconv"
1313
"strings"
1414

15-
"google.golang.org/grpc/codes"
1615
"github.com/pkg/browser"
1716
ybApi "github.com/yottab/proto-api/proto"
17+
"google.golang.org/grpc/codes"
1818

1919
"google.golang.org/grpc/status"
2020
"k8s.io/client-go/rest"
@@ -23,7 +23,7 @@ import (
2323
//For windows support
2424
)
2525

26-
func printCount(size int){
26+
func printCount(size int) {
2727
fmt.Println(secTxtColor("# Count: %d ", size))
2828
}
2929

@@ -84,7 +84,7 @@ func uiList(list interface{}) {
8484
case *ybApi.VolumeListRes:
8585
itemList := list.(*ybApi.VolumeListRes)
8686
printCount(len(itemList.Volumes))
87-
for _, v := range itemList.Volumes {
87+
for _, v := range itemList.Volumes {
8888
uiVolumeStatus(v)
8989
}
9090
return
@@ -100,12 +100,14 @@ func uiList(list interface{}) {
100100
}
101101
}
102102

103-
func uiVolumeMount(space string, vm []*ybApi.VolumeMount){
104-
if len(vm) == 0 { return }
103+
func uiVolumeMount(space string, vm []*ybApi.VolumeMount) {
104+
if len(vm) == 0 {
105+
return
106+
}
105107
printKeyVal(space, "Mount", "")
106108
for _, m := range vm {
107-
printKeyVal(space + whiteSpaceDash, "To", m.GetAttachment())
108-
printKeyVal(space + whiteSpace, "Path", m.GetMountPath())
109+
printKeyVal(space+whiteSpaceDash, "To", m.GetAttachment())
110+
printKeyVal(space+whiteSpace, "Path", m.GetMountPath())
109111
}
110112
}
111113

@@ -116,8 +118,10 @@ func uiImageInfo(res *ybApi.ImgStatusRes) {
116118
printKeyVal(whiteSpace, "Updated", toTime(res.Updated))
117119
}
118120

119-
func uiConditions(space string, conditions []*ybApi.ServiceCondition){
120-
if len(conditions) == 0 { return }
121+
func uiConditions(space string, conditions []*ybApi.ServiceCondition) {
122+
if len(conditions) == 0 {
123+
return
124+
}
121125
if len(conditions) == 1 {
122126
c := conditions[0]
123127
cond := fmt.Sprintf("%s (%s)", c.GetCondition(), c.GetReason())
@@ -126,14 +130,16 @@ func uiConditions(space string, conditions []*ybApi.ServiceCondition){
126130
}
127131
for i, c := range conditions {
128132
cond := fmt.Sprintf("%s (%s)", c.GetCondition(), c.GetReason())
129-
printKeyVal(space + whiteSpaceDash, "Index", strconv.Itoa(i))
130-
printKeyVal(space + whiteSpace, "Condition", cond)
133+
printKeyVal(space+whiteSpaceDash, "Index", strconv.Itoa(i))
134+
printKeyVal(space+whiteSpace, "Condition", cond)
131135
}
132136
}
133137

134138
func uiStringArray(space, title string, arr []string) {
135-
if len(arr) == 0 { return }
136-
139+
if len(arr) == 0 {
140+
return
141+
}
142+
137143
tags := fmt.Sprintf("[%s]", strings.Join(arr, ","))
138144
printKeyVal(space, title, tags)
139145
}
@@ -149,11 +155,6 @@ func uiServicStatus(srv *ybApi.SrvStatusRes) {
149155
printKeyVal(whiteSpace, "Updated", toTime(srv.Updated))
150156
}
151157

152-
func uiNFSMount(in *ybApi.PortforwardRes) {
153-
log.Printf("FTP portforwarding is ready @ localhost:21")
154-
log.Printf("Now you can connect using your favorite ftp client, e.g. filezilla...")
155-
}
156-
157158
func uiPortforward(in *ybApi.PortforwardRes) {
158159
bearer := string(in.Token)
159160
localPorts := []string{}
@@ -190,7 +191,7 @@ func uiPortforward(in *ybApi.PortforwardRes) {
190191
colorfulPrintln(whiteSpace)
191192
colorfulPrintln(whiteSpace)
192193
colorfulPrintln(whiteSpace)
193-
colorfulPrintln(whiteSpace , mainTxtSprint(" Now local ports are accessible from localhost: "))
194+
colorfulPrintln(whiteSpace, mainTxtSprint(" Now local ports are accessible from localhost: "))
194195
for _, p := range localPorts {
195196
fports := strings.Split(p, ":")
196197
colorfulPrint(whiteSpace)
@@ -203,7 +204,9 @@ func uiPortforward(in *ybApi.PortforwardRes) {
203204

204205
<-signals
205206
fmt.Print(secTitleColor(" Closing ports... "))
206-
if done != nil { close(done) }
207+
if done != nil {
208+
close(done)
209+
}
207210
fmt.Println(secTitleBlink(" done "))
208211
os.Exit(1)
209212

@@ -220,54 +223,64 @@ func uiPortforward(in *ybApi.PortforwardRes) {
220223
}
221224

222225
func uiPlan(space string, plan []*ybApi.Plan) {
223-
if len(plan) == 0 { return }
226+
if len(plan) == 0 {
227+
return
228+
}
224229

225230
printKeyVal(space, "Plan", "")
226231
for _, p := range plan {
227-
printKeyVal(space + whiteSpaceDash, "Name", p.Name)
228-
printKeyVal(space + whiteSpace, "Description", p.Description)
229-
uiMapStrStr(space + whiteSpace, "Extras", p.Extras)
232+
printKeyVal(space+whiteSpaceDash, "Name", p.Name)
233+
printKeyVal(space+whiteSpace, "Description", p.Description)
234+
uiMapStrStr(space+whiteSpace, "Extras", p.Extras)
230235
}
231236
}
232237

233238
func uiMapGeneralVariable(space string, mapVar map[string]*ybApi.GeneralVariable) {
234-
if len(mapVar) == 0 { return }
239+
if len(mapVar) == 0 {
240+
return
241+
}
235242

236243
printKeyVal(space, "General_Variables", "")
237244
for k, v := range mapVar {
238-
printKeyVal(space + whiteSpace, k, v.GetValue())
245+
printKeyVal(space+whiteSpace, k, v.GetValue())
239246
}
240247
}
241248

242249
func uiMapStrStr(space, name string, mapVar map[string]string) {
243-
if len(mapVar) == 0 { return }
250+
if len(mapVar) == 0 {
251+
return
252+
}
244253

245254
printKeyVal(space, name, "")
246255
for k, v := range mapVar {
247-
printKeyVal(space + whiteSpace, k, v)
256+
printKeyVal(space+whiteSpace, k, v)
248257
}
249258
}
250259

251260
func uiRoutes(space string, mapVar []*ybApi.DomainAttachedTo) {
252-
if len(mapVar) == 0 { return }
261+
if len(mapVar) == 0 {
262+
return
263+
}
253264

254265
printKeyVal(space, "Variables", "")
255266
for _, v := range mapVar {
256-
printKeyVal(space + whiteSpaceDash, "To", v.GetName())
257-
printKeyVal(space + whiteSpace, "Path", v.GetPath())
258-
printKeyVal(space + whiteSpace, "EndPoint", v.GetEndpoint())
267+
printKeyVal(space+whiteSpaceDash, "To", v.GetName())
268+
printKeyVal(space+whiteSpace, "Path", v.GetPath())
269+
printKeyVal(space+whiteSpace, "EndPoint", v.GetEndpoint())
259270
mainTxtPrintln(space + whiteSpace)
260271
}
261272
}
262273

263-
func uiYamlMultiLineStr(space, name, val string){
264-
if val == "" { return }
274+
func uiYamlMultiLineStr(space, name, val string) {
275+
if val == "" {
276+
return
277+
}
265278

266279
printKeyVal(space, name, "|")
267280
lines := strings.Split(strings.Replace(val, "\r\n", "\n", -1), "\n")
268281
for _, line := range lines {
269282
fmt.Println(
270-
space + whiteSpace,
283+
space+whiteSpace,
271284
secTxtColor(line))
272285
}
273286
}
@@ -286,11 +299,11 @@ func uiPrdVar(space string, variables map[string]*ybApi.GeneralVariable) {
286299
} else {
287300
printKeyVal(space, "Variables", "")
288301
for _, v := range variables {
289-
printKeyVal(space + whiteSpaceDash, "Name", v.Name)
290-
printKeyVal(space + whiteSpace, "Required", strconv.FormatBool(v.IsRequired))
291-
printKeyVal(space + whiteSpace, "Type", v.Type)
292-
printKeyVal(space + whiteSpace, "Default", v.DefaultValue)
293-
printKeyVal(space + whiteSpace, "Description", v.Description)
302+
printKeyVal(space+whiteSpaceDash, "Name", v.Name)
303+
printKeyVal(space+whiteSpace, "Required", strconv.FormatBool(v.IsRequired))
304+
printKeyVal(space+whiteSpace, "Type", v.Type)
305+
printKeyVal(space+whiteSpace, "Default", v.DefaultValue)
306+
printKeyVal(space+whiteSpace, "Description", v.Description)
294307
mainTxtPrintln(space + whiteSpace)
295308
}
296309
}
@@ -302,7 +315,7 @@ func uiApplicationOpen(app *ybApi.AppStatusRes) {
302315
}
303316
//We only recieve one route at this moment!
304317
route := app.Routes[0]
305-
if !strings.HasPrefix("http", route){
318+
if !strings.HasPrefix("http", route) {
306319
println(secTitleColor("Can't open this type of endpoints right now!"))
307320
} else if err := browser.OpenURL(route); err != nil {
308321
fmt.Printf("Can't open this endpoint, error: %v!", err)
@@ -311,15 +324,17 @@ func uiApplicationOpen(app *ybApi.AppStatusRes) {
311324
}
312325
}
313326

314-
func uiAppInstances(space string, instances []*ybApi.Instance){
315-
if len(instances) == 0 { return }
327+
func uiAppInstances(space string, instances []*ybApi.Instance) {
328+
if len(instances) == 0 {
329+
return
330+
}
316331

317332
printKeyVal(space, "Instances", "")
318333
for _, v := range instances {
319-
printKeyVal(space + whiteSpaceDash, "ID", v.Name)
320-
printKeyVal(space + whiteSpace, "CPU", v.Cpu)
321-
printKeyVal(space + whiteSpace, "RAM", v.Ram)
322-
printKeyVal(space + whiteSpace, "Created", toTime(v.Created))
334+
printKeyVal(space+whiteSpaceDash, "ID", v.Name)
335+
printKeyVal(space+whiteSpace, "CPU", v.Cpu)
336+
printKeyVal(space+whiteSpace, "RAM", v.Ram)
337+
printKeyVal(space+whiteSpace, "Created", toTime(v.Created))
323338
mainTxtPrintln(space + whiteSpace)
324339
}
325340
}
@@ -347,13 +362,15 @@ func jsonPrettyPrint(in string) string {
347362
}
348363

349364
func uiAttachedDomains(space string, domains []*ybApi.AttachedDomainInfo) {
350-
if len(domains) == 0 { return }
365+
if len(domains) == 0 {
366+
return
367+
}
351368

352369
printKeyVal(space, "Attached_Domains", "")
353370
for _, v := range domains {
354-
printKeyVal(space + whiteSpaceDash, "Domain", v.Domain)
355-
printKeyVal(space + whiteSpace, "Endpoint", v.Endpoint)
356-
printKeyVal(space + whiteSpace, "Type", v.EndpointType)
371+
printKeyVal(space+whiteSpaceDash, "Domain", v.Domain)
372+
printKeyVal(space+whiteSpace, "Endpoint", v.Endpoint)
373+
printKeyVal(space+whiteSpace, "Type", v.EndpointType)
357374
mainTxtPrintln(space + whiteSpace)
358375
}
359376
}
@@ -384,9 +401,9 @@ func uiDomainStatus(v *ybApi.DomainStatusRes) {
384401
}
385402

386403
func uiVolumeSpec(space string, vol *ybApi.VolumeSpec) {
387-
printKeyVal(space + whiteSpaceDash, "Name", vol.Name)
388-
printKeyVal(space + whiteSpace, "Class", vol.Class)
389-
printKeyVal(space + whiteSpace, "Size", vol.Size)
404+
printKeyVal(space+whiteSpaceDash, "Name", vol.Name)
405+
printKeyVal(space+whiteSpace, "Class", vol.Class)
406+
printKeyVal(space+whiteSpace, "Size", vol.Size)
390407
}
391408

392409
func uiVolumeStatus(v *ybApi.VolumeStatusRes) {

0 commit comments

Comments
 (0)