Skip to content

Commit cf2dbf5

Browse files
committed
Started ota file id path support
1 parent 126ef44 commit cf2dbf5

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

cli/ota/status.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ import (
2929
)
3030

3131
type statusFlags struct {
32-
otaID string
33-
deviceId string
34-
wide bool
32+
otaID string
33+
deviceId string
34+
otaIdsFilePath string
35+
wide bool
3536
}
3637

3738
func initOtaStatusCommand() *cobra.Command {
@@ -49,20 +50,21 @@ func initOtaStatusCommand() *cobra.Command {
4950
}
5051
uploadCommand.Flags().StringVarP(&flags.otaID, "ota-id", "o", "", "OTA ID")
5152
uploadCommand.Flags().StringVarP(&flags.deviceId, "device-id", "d", "", "Device ID")
53+
uploadCommand.Flags().StringVarP(&flags.otaIdsFilePath, "ota-ids", "i", "", "OTA IDs file path. If set, the command will read the OTA IDs from the file and get the status for each OTA ID.")
5254
uploadCommand.Flags().BoolVarP(&flags.wide, "wide", "w", false, "Show more status details")
5355

5456
return uploadCommand
5557
}
5658

5759
func runOtaStatusCommand(flags *statusFlags) error {
58-
if flags.otaID == "" && flags.deviceId == "" {
59-
return fmt.Errorf("required flag(s) \"ota-id\" or \"device-id\" not set")
60+
if flags.otaID == "" && flags.deviceId == "" && flags.otaIdsFilePath == "" {
61+
return fmt.Errorf("required flag(s) \"ota-id\" or \"device-id\" or \"ota-ids\" not set")
6062
}
6163

6264
cred, err := config.RetrieveCredentials()
6365
if err != nil {
6466
return fmt.Errorf("retrieving credentials: %w", err)
6567
}
6668

67-
return ota.PrintOtaStatus(flags.otaID, flags.deviceId, flags.wide, cred)
69+
return ota.PrintOtaStatus(flags.otaID, flags.deviceId, flags.otaIdsFilePath, flags.wide, cred)
6870
}

command/ota/status.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
func formatOutput(wideOutput bool, status any) {
1212
if st, ok := status.(otaapi.Ota); ok {
1313
if !wideOutput {
14-
st.ID = ""
1514
st.DeviceID = ""
1615
st.ErrorReason = ""
1716
st.Sha256 = ""
@@ -26,7 +25,6 @@ func formatOutputSlice(wideOutput bool, st []otaapi.Ota) {
2625
}
2726
for i := range st {
2827
if !wideOutput {
29-
st[i].ID = ""
3028
st[i].DeviceID = ""
3129
st[i].ErrorReason = ""
3230
st[i].Sha256 = ""
@@ -42,22 +40,24 @@ func printJson(res any) {
4240
}
4341
}
4442

45-
func PrintOtaStatus(otaid, device string, wideOutput bool, cred *config.Credentials) error {
43+
func PrintOtaStatus(otaid, device, otaidpath string, wideOutput bool, cred *config.Credentials) error {
4644
otapi := otaapi.NewClient(cred)
4745

4846
var err error
49-
if otaid != "" {
47+
if otaidpath != "" {
48+
49+
} else if otaid != "" {
5050
res, err := otapi.GetOtaStatusByOtaID(otaid)
5151
if err == nil && res != nil {
5252
formatOutput(wideOutput, res.Ota)
5353
}
54-
}
55-
if device != "" {
54+
} else if device != "" {
5655
res, err := otapi.GetOtaStatusByDeviceID(device)
5756
if err == nil && res != nil {
5857
formatOutputSlice(wideOutput, res.Ota)
5958
}
6059
}
60+
6161
if err != nil {
6262
return err
6363
}

0 commit comments

Comments
 (0)