Skip to content

Commit 3b20476

Browse files
committed
output fixes
1 parent c5f14b0 commit 3b20476

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

command/ota/status.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"gopkg.in/yaml.v3"
1111
)
1212

13-
func formatOtaByIdOutput(wideOutput bool, st *otaapi.OtaStatusResponse) {
13+
func formatOtaByIdOutput(wideOutput bool, st *otaapi.OtaStatusPrint) {
1414
if !wideOutput {
1515
st.Ota.DeviceID = ""
1616
st.Ota.ErrorReason = ""
@@ -89,7 +89,10 @@ func PrintOtaStatus(otaid, device, otaidpath string, wideOutput bool, cred *conf
8989
} else if otaid != "" {
9090
res, err := otapi.GetOtaStatusByOtaID(otaid)
9191
if err == nil && res != nil {
92-
formatOtaByIdOutput(wideOutput, res)
92+
formatOtaByIdOutput(wideOutput, &otaapi.OtaStatusPrint{
93+
Ota: res.Ota,
94+
Details: res.States,
95+
})
9396
} else if err != nil {
9497
return err
9598
}

internal/ota-api/dto.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -45,32 +45,41 @@ type (
4545
StateData string `json:"state_data,omitempty"`
4646
Timestamp string `json:"timestamp,omitempty"`
4747
}
48+
49+
OtaStatusPrint struct {
50+
Ota Ota `json:"ota"`
51+
Details []State `json:"details,omitempty"`
52+
}
4853
)
4954

5055
func (o Ota) GetWideCSVHeader() string {
51-
return "id,device_id,status,started_at,ended_at,error_reason"
56+
return "ota_id,device_id,status,started_at,ended_at,error_reason"
5257
}
5358

5459
func (o Ota) ToWideCSV() string {
5560
return fmt.Sprintf("%s,%s,%s,%s,%s,%s", o.ID, o.DeviceID, o.Status, o.StartedAt, o.EndedAt, o.ErrorReason)
5661
}
5762

5863
func (o Ota) GetCSVHeader() string {
59-
return "id,status,started_at,ended_at"
64+
return "ota_id,status,started_at,ended_at"
6065
}
6166

6267
func (o Ota) ToCSV() string {
6368
return fmt.Sprintf("%s,%s,%s,%s", o.ID, o.Status, o.StartedAt, o.EndedAt)
6469
}
6570

6671
func (o Ota) ToText() string {
67-
out := fmt.Sprintf("ID: %s\nStatus: %s\nStartedAt: %s\nEndedAt: %s", o.ID, o.Status, o.StartedAt, o.EndedAt)
72+
out := fmt.Sprintf("ota_id: %s\nstatus: %s\nstarted_at: %s\nended_at: %s", o.ID, o.Status, o.StartedAt, o.EndedAt)
6873
if o.ErrorReason != "" {
69-
out += fmt.Sprintf("\nErrorReason: %s", o.ErrorReason)
74+
out += fmt.Sprintf("\nerror_reason: %s", o.ErrorReason)
7075
}
7176
return out
7277
}
7378

7479
func (s State) ToText() string {
75-
return fmt.Sprintf("Timestamp: %s, State: %s", s.Timestamp, s.State)
80+
rep := fmt.Sprintf("time: %s, status: %s", s.Timestamp, s.State)
81+
if s.StateData != "" {
82+
rep += fmt.Sprintf(", detail: %s", s.StateData)
83+
}
84+
return rep
7685
}

0 commit comments

Comments
 (0)