@@ -8,29 +8,60 @@ import (
8
8
otaapi "github.com/arduino/arduino-cloud-cli/internal/ota-api"
9
9
)
10
10
11
- func PrintOtaStatus (otaid , device string , cred * config.Credentials ) error {
11
+ func formatOutput (wideOutput bool , status any ) {
12
+ if st , ok := status .(otaapi.Ota ); ok {
13
+ if ! wideOutput {
14
+ st .ID = ""
15
+ st .DeviceID = ""
16
+ st .ErrorReason = ""
17
+ st .Sha256 = ""
18
+ }
19
+ printJson (st )
20
+ }
21
+ }
22
+
23
+ func formatOutputSlice (wideOutput bool , st []otaapi.Ota ) {
24
+ if st == nil {
25
+ st = []otaapi.Ota {}
26
+ }
27
+ for i := range st {
28
+ if ! wideOutput {
29
+ st [i ].ID = ""
30
+ st [i ].DeviceID = ""
31
+ st [i ].ErrorReason = ""
32
+ st [i ].Sha256 = ""
33
+ }
34
+ }
35
+ printJson (st )
36
+ }
37
+
38
+ func printJson (res any ) {
39
+ jsonRes , _ := json .MarshalIndent (res , "" , " " )
40
+ if jsonRes != nil {
41
+ fmt .Println (string (jsonRes ))
42
+ }
43
+ }
44
+
45
+ func PrintOtaStatus (otaid , device string , wideOutput bool , cred * config.Credentials ) error {
12
46
otapi := otaapi .NewClient (cred )
13
47
14
48
var res any
15
49
var err error
16
50
if otaid != "" {
17
51
res , err = otapi .GetOtaStatusByOtaID (otaid )
18
52
if err == nil {
19
- res = res .(* otaapi.OtaStatusResponse ).Ota
53
+ formatOutput ( wideOutput , res .(* otaapi.OtaStatusResponse ).Ota )
20
54
}
21
55
}
22
56
if device != "" {
23
57
res , err = otapi .GetOtaStatusByDeviceID (device )
24
58
if err == nil {
25
- res = res .(* otaapi.OtaStatusByDeviceResponse ).Ota
59
+ formatOutputSlice ( wideOutput , res .(* otaapi.OtaStatusByDeviceResponse ).Ota )
26
60
}
27
61
}
28
62
if err != nil {
29
63
return err
30
64
}
31
65
32
- jsonRes , _ := json .MarshalIndent (res , "" , "\t " )
33
- fmt .Println (string (jsonRes ))
34
-
35
66
return nil
36
67
}
0 commit comments