Skip to content

Commit e43d191

Browse files
committed
Prettify status sync
1 parent de39a20 commit e43d191

2 files changed

Lines changed: 36 additions & 13 deletions

File tree

cmd/list.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,14 @@ func (cmd *ListCmd) RunListSync(cobraCmd *cobra.Command, args []string) {
176176
excludedPaths += v
177177
}
178178
}
179+
180+
resourceType := "pod"
181+
if value.ResourceType != nil {
182+
resourceType = *value.ResourceType
183+
}
184+
179185
syncPaths = append(syncPaths, []string{
180-
*value.ResourceType,
186+
resourceType,
181187
selector,
182188
*value.LocalSubPath,
183189
*value.ContainerPath,
@@ -208,7 +214,6 @@ func (cmd *ListCmd) RunListPort(cobraCmd *cobra.Command, args []string) {
208214
// Transform values into string arrays
209215
for _, value := range *config.DevSpace.PortForwarding {
210216
selector := ""
211-
212217
for k, v := range *value.LabelSelector {
213218
if len(selector) > 0 {
214219
selector += ", "
@@ -218,7 +223,6 @@ func (cmd *ListCmd) RunListPort(cobraCmd *cobra.Command, args []string) {
218223
}
219224

220225
portMappings := ""
221-
222226
for _, v := range *value.PortMappings {
223227
if len(portMappings) > 0 {
224228
portMappings += ", "
@@ -227,8 +231,13 @@ func (cmd *ListCmd) RunListPort(cobraCmd *cobra.Command, args []string) {
227231
portMappings += strconv.Itoa(*v.LocalPort) + ":" + strconv.Itoa(*v.RemotePort)
228232
}
229233

234+
resourceType := "pod"
235+
if value.ResourceType != nil {
236+
resourceType = *value.ResourceType
237+
}
238+
230239
portForwards = append(portForwards, []string{
231-
*value.ResourceType,
240+
resourceType,
232241
selector,
233242
portMappings,
234243
})

cmd/status_sync.go

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,27 @@ func (cmd *StatusCmd) RunStatusSync(cobraCmd *cobra.Command, args []string) {
9494
}
9595

9696
parsedTime, _ := time.Parse(time.RFC3339, status.LastActivityTime)
97+
if parsedTime.Unix() == 0 {
98+
parsedTime = time.Now()
99+
}
100+
97101
latestActivity += " (" + intToTimeString(int(time.Now().Unix()-parsedTime.Unix())) + " ago)"
98102

99103
syncStatus := status.Status
100104
if syncStatus == "" {
101105
syncStatus = "Active"
102106
}
103107

108+
if len(status.Pod) > 15 {
109+
status.Pod = status.Pod[:15] + "..."
110+
}
111+
if len(status.Local) > 20 {
112+
status.Local = "..." + status.Local[len(status.Local)-20:len(status.Local)]
113+
}
114+
if len(status.Container) > 20 {
115+
status.Container = "..." + status.Container[len(status.Container)-20:len(status.Container)]
116+
}
117+
104118
values = append(values, []string{
105119
syncStatus,
106120
status.Pod,
@@ -118,39 +132,39 @@ func intToTimeString(timeDifference int) string {
118132
days := math.Floor(float64(timeDifference) / (60.0 * 60.0 * 24.0))
119133
if days > 0 {
120134
if days == 1 {
121-
return "1 day"
135+
return "1d"
122136
}
123137

124-
return strconv.Itoa(int(days)) + " days"
138+
return strconv.Itoa(int(days)) + "d"
125139
}
126140

127141
hours := math.Floor(float64(timeDifference) / (60.0 * 60.0))
128142
if hours > 0 {
129143
if hours == 1 {
130-
return "1 hour"
144+
return "1h"
131145
}
132146

133-
return strconv.Itoa(int(hours)) + " hours"
147+
return strconv.Itoa(int(hours)) + "h"
134148
}
135149

136150
minutes := math.Floor(float64(timeDifference) / 60.0)
137151
if minutes > 0 {
138152
if minutes == 1 {
139-
return "1 minute"
153+
return "1m"
140154
}
141155

142-
return strconv.Itoa(int(minutes)) + " minutes"
156+
return strconv.Itoa(int(minutes)) + "m"
143157
}
144158

145159
if timeDifference > 0 {
146160
if timeDifference == 1 {
147-
return "1 seconds"
161+
return "1s"
148162
}
149163

150-
return strconv.Itoa(timeDifference) + " seconds"
164+
return strconv.Itoa(timeDifference) + "s"
151165
}
152166

153-
return "0 seconds"
167+
return "0s"
154168
}
155169

156170
func isSyncJSONMapInvalid(jsonMap map[string]string) bool {

0 commit comments

Comments
 (0)