File tree 1 file changed +15
-13
lines changed
1 file changed +15
-13
lines changed Original file line number Diff line number Diff line change 18
18
package otaapi
19
19
20
20
import (
21
+ "strings"
21
22
"time"
22
23
24
+ "unicode"
25
+
23
26
"github.com/arduino/arduino-cli/table"
24
27
)
25
28
@@ -92,18 +95,7 @@ func (r OtaStatusByDeviceResponse) String() string {
92
95
}
93
96
94
97
func (o Ota ) MapStatus () string {
95
- switch o .Status {
96
- case "in_progress" :
97
- return "In progress"
98
- case "failed" :
99
- return "Failed"
100
- case "pending" :
101
- return "Pending"
102
- case "succeeded" :
103
- return "Succeeded"
104
- default :
105
- return o .Status
106
- }
98
+ return upperCaseFirst (o .Status )
107
99
}
108
100
109
101
func (r Ota ) Data () interface {} {
@@ -164,14 +156,24 @@ func (r OtaStatusPrint) String() string {
164
156
t = table .New ()
165
157
t .SetHeader ("Time" , "Status" , "Detail" )
166
158
for _ , s := range r .Details {
167
- t .AddRow (formatHumanReadableTs (s .Timestamp ), s .State , s .StateData )
159
+ t .AddRow (formatHumanReadableTs (s .Timestamp ), upperCaseFirst ( s .State ) , s .StateData )
168
160
}
169
161
output += "\n Details:\n " + t .Render ()
170
162
}
171
163
172
164
return output
173
165
}
174
166
167
+ func upperCaseFirst (s string ) string {
168
+ if len (s ) > 0 {
169
+ s = strings .ReplaceAll (s , "_" , " " )
170
+ for i , v := range s {
171
+ return string (unicode .ToUpper (v )) + s [i + 1 :]
172
+ }
173
+ }
174
+ return ""
175
+ }
176
+
175
177
func formatHumanReadableTs (ts string ) string {
176
178
if ts == "" {
177
179
return ""
You can’t perform that action at this time.
0 commit comments