Skip to content

Commit d0950a5

Browse files
committed
Better upper case
1 parent 89e9776 commit d0950a5

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

internal/ota-api/dto.go

+15-13
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
package otaapi
1919

2020
import (
21+
"strings"
2122
"time"
2223

24+
"unicode"
25+
2326
"github.com/arduino/arduino-cli/table"
2427
)
2528

@@ -92,18 +95,7 @@ func (r OtaStatusByDeviceResponse) String() string {
9295
}
9396

9497
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)
10799
}
108100

109101
func (r Ota) Data() interface{} {
@@ -164,14 +156,24 @@ func (r OtaStatusPrint) String() string {
164156
t = table.New()
165157
t.SetHeader("Time", "Status", "Detail")
166158
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)
168160
}
169161
output += "\nDetails:\n" + t.Render()
170162
}
171163

172164
return output
173165
}
174166

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+
175177
func formatHumanReadableTs(ts string) string {
176178
if ts == "" {
177179
return ""

0 commit comments

Comments
 (0)