Skip to content

Commit 866f993

Browse files
committed
Added ota feedback on execution
1 parent 4425e00 commit 866f993

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

command/ota/upload.go

+13
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
"github.com/arduino/arduino-cloud-cli/config"
2727
"github.com/arduino/arduino-cloud-cli/internal/iot"
28+
otaapi "github.com/arduino/arduino-cloud-cli/internal/ota-api"
2829
)
2930

3031
const (
@@ -49,6 +50,10 @@ func Upload(ctx context.Context, params *UploadParams, cred *config.Credentials)
4950
if err != nil {
5051
return err
5152
}
53+
otapi := otaapi.NewClient(cred)
54+
if err != nil {
55+
return err
56+
}
5257

5358
dev, err := iotClient.DeviceShow(ctx, params.DeviceID)
5459
if err != nil {
@@ -82,6 +87,14 @@ func Upload(ctx context.Context, params *UploadParams, cred *config.Credentials)
8287
if err != nil {
8388
return err
8489
}
90+
// Try to get ota-id from API
91+
otaID, err := otapi.GetOtaStatusByDeviceID(params.DeviceID, 1, otaapi.OrderDesc)
92+
if err != nil {
93+
return err
94+
}
95+
if otaID != nil && len(otaID.Ota) > 0 {
96+
otaID.Ota[0].Format()
97+
}
8598

8699
return nil
87100
}

internal/ota-api/client.go

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ import (
3232
"golang.org/x/oauth2"
3333
)
3434

35+
const OrderDesc = "desc"
36+
const OrderAsc = "asc"
37+
3538
type OtaApiClient struct {
3639
client *http.Client
3740
host string

internal/ota-api/dto.go

+23
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818
package otaapi
1919

2020
import (
21+
"encoding/json"
2122
"fmt"
2223
"time"
24+
25+
"github.com/arduino/arduino-cli/cli/feedback"
26+
"gopkg.in/yaml.v3"
2327
)
2428

2529
type (
@@ -70,6 +74,25 @@ func (o Ota) ToText() string {
7074
return out
7175
}
7276

77+
func (o Ota) Format() {
78+
outputformat := feedback.GetFormat()
79+
if outputformat == feedback.JSON || outputformat == feedback.JSONMini {
80+
jsonRes, _ := json.MarshalIndent(o, "", " ")
81+
if jsonRes != nil {
82+
fmt.Println(string(jsonRes))
83+
}
84+
}
85+
if outputformat == feedback.YAML {
86+
yamlRes, _ := yaml.Marshal(o)
87+
if yamlRes != nil {
88+
fmt.Println(string(yamlRes))
89+
}
90+
}
91+
if outputformat == feedback.Text {
92+
fmt.Println(o.ToLine())
93+
}
94+
}
95+
7396
func (s State) ToText() string {
7497
rep := fmt.Sprintf("time: %s, status: %s", formatHumanReadableTs(s.Timestamp), s.State)
7598
if s.StateData != "" {

0 commit comments

Comments
 (0)