@@ -4,8 +4,10 @@ import (
4
4
"encoding/json"
5
5
"fmt"
6
6
7
+ "github.com/arduino/arduino-cli/cli/feedback"
7
8
"github.com/arduino/arduino-cloud-cli/config"
8
9
otaapi "github.com/arduino/arduino-cloud-cli/internal/ota-api"
10
+ "gopkg.in/yaml.v3"
9
11
)
10
12
11
13
func formatOutput (wideOutput bool , status any ) {
@@ -15,7 +17,7 @@ func formatOutput(wideOutput bool, status any) {
15
17
st .ErrorReason = ""
16
18
st .Sha256 = ""
17
19
}
18
- printJson (st )
20
+ printOut (st , wideOutput )
19
21
}
20
22
}
21
23
@@ -30,37 +32,78 @@ func formatOutputSlice(wideOutput bool, st []otaapi.Ota) {
30
32
st [i ].Sha256 = ""
31
33
}
32
34
}
33
- printJson (st )
35
+ printOut (st , wideOutput )
34
36
}
35
37
36
- func printJson (res any ) {
37
- jsonRes , _ := json .MarshalIndent (res , "" , " " )
38
- if jsonRes != nil {
39
- fmt .Println (string (jsonRes ))
38
+ func printOut (res any , wideOutput bool ) {
39
+ outputformat := feedback .GetFormat ()
40
+ if outputformat == feedback .JSON || outputformat == feedback .JSONMini {
41
+ jsonRes , _ := json .MarshalIndent (res , "" , " " )
42
+ if jsonRes != nil {
43
+ fmt .Println (string (jsonRes ))
44
+ }
45
+ }
46
+ if outputformat == feedback .YAML {
47
+ yamlRes , _ := yaml .Marshal (res )
48
+ if yamlRes != nil {
49
+ fmt .Println (string (yamlRes ))
50
+ }
51
+ }
52
+ if outputformat == feedback .Text {
53
+ if st , ok := res .(otaapi.Ota ); ok {
54
+ if wideOutput {
55
+ fmt .Println (st .GetWideCSVHeader ())
56
+ fmt .Println (st .ToWideCSV ())
57
+ } else {
58
+ fmt .Println (st .GetCSVHeader ())
59
+ fmt .Println (st .ToCSV ())
60
+ }
61
+ }
62
+ if st , ok := res .([]otaapi.Ota ); ok {
63
+
64
+ for i := range st {
65
+ if i == 0 {
66
+ if wideOutput {
67
+ fmt .Println (st [i ].GetWideCSVHeader ())
68
+ } else {
69
+ fmt .Println (st [i ].GetCSVHeader ())
70
+ }
71
+ }
72
+ if wideOutput {
73
+ fmt .Println (st [i ].ToWideCSV ())
74
+ } else {
75
+ fmt .Println (st [i ].ToCSV ())
76
+ }
77
+ }
78
+ }
40
79
}
41
80
}
42
81
43
82
func PrintOtaStatus (otaid , device , otaidpath string , wideOutput bool , cred * config.Credentials ) error {
83
+
84
+ if feedback .GetFormat () == feedback .JSONMini {
85
+ return fmt .Errorf ("jsonmini format is not supported for this command" )
86
+ }
87
+
44
88
otapi := otaapi .NewClient (cred )
45
89
46
- var err error
47
90
if otaidpath != "" {
48
-
91
+ // TODO: implement
49
92
} else if otaid != "" {
50
93
res , err := otapi .GetOtaStatusByOtaID (otaid )
51
94
if err == nil && res != nil {
52
95
formatOutput (wideOutput , res .Ota )
96
+ } else if err != nil {
97
+ return err
53
98
}
54
99
} else if device != "" {
55
100
res , err := otapi .GetOtaStatusByDeviceID (device )
56
101
if err == nil && res != nil {
57
102
formatOutputSlice (wideOutput , res .Ota )
103
+ } else if err != nil {
104
+ return err
58
105
}
59
106
}
60
107
61
- if err != nil {
62
- return err
63
- }
64
-
65
108
return nil
66
109
}
0 commit comments