Skip to content

Commit a78ee26

Browse files
committed
Started refactoring to move to client v2
1 parent e7a4495 commit a78ee26

21 files changed

+105
-56
lines changed

command/dashboard/create.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ func Create(ctx context.Context, params *CreateParams, cred *config.Credentials)
4747

4848
// Name passed as parameter has priority over name from template
4949
if params.Name != nil {
50-
dashboard.Name = *params.Name
50+
dashboard.Name = params.Name
5151
}
5252
// If name is not specified in the template, it should be passed as parameter
53-
if dashboard.Name == "" {
53+
if dashboard.Name == nil || *dashboard.Name == "" {
5454
return nil, errors.New("dashboard name not specified")
5555
}
5656

command/dashboard/dashboard.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ type DashboardInfo struct {
3333
func getDashboardInfo(dashboard *iotclient.ArduinoDashboardv2) *DashboardInfo {
3434
var widgets []string
3535
for _, w := range dashboard.Widgets {
36-
widgets = append(widgets, w.Name)
36+
if w.Name != nil {
37+
widgets = append(widgets, *w.Name)
38+
}
3739
}
3840
info := &DashboardInfo{
3941
Name: dashboard.Name,

command/device/create.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,14 @@ func Create(ctx context.Context, params *CreateParams, cred *config.Credentials)
100100
ID: dev.Id,
101101
Board: dev.Type,
102102
Serial: dev.Serial,
103-
FQBN: dev.Fqbn,
103+
FQBN: dereferenceString(dev.Fqbn),
104104
}
105105
return devInfo, nil
106106
}
107+
108+
func dereferenceString(s *string) string {
109+
if s == nil {
110+
return ""
111+
}
112+
return *s
113+
}

command/device/creategeneric.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ func CreateGeneric(ctx context.Context, params *CreateGenericParams, cred *confi
7575
ID: dev.Id,
7676
Board: dev.Type,
7777
Serial: dev.Serial,
78-
FQBN: dev.Fqbn,
78+
FQBN: dereferenceString(dev.Fqbn),
7979
},
80-
Password: pass.SuggestedPassword,
80+
Password: dereferenceString(pass.SuggestedPassword),
8181
}
8282
return devInfo, nil
8383
}

command/device/createlora.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func getDeviceLoraInfo(ctx context.Context, iotClient *iot.Client, loraDev *iotc
181181
ID: dev.Id,
182182
Board: dev.Type,
183183
Serial: dev.Serial,
184-
FQBN: dev.Fqbn,
184+
FQBN: dereferenceString(dev.Fqbn),
185185
},
186186
AppEUI: loraDev.AppEui,
187187
AppKey: loraDev.AppKey,

command/device/device.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func getDeviceInfo(device *iotclient.ArduinoDevicev2) (*DeviceInfo, error) {
4545
ID: device.Id,
4646
Board: device.Type,
4747
Serial: device.Serial,
48-
FQBN: device.Fqbn,
48+
FQBN: dereferenceString(device.Fqbn),
4949
Tags: tags,
5050
}
5151
return dev, nil

command/device/provision.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ func (p provision) configBoard(ctx context.Context) error {
185185
}
186186

187187
logrus.Info("Sending certificate authority key")
188-
b, err = hex.DecodeString(cert.AuthorityKeyIdentifier)
188+
b, err = hex.DecodeString(dereferenceString(cert.AuthorityKeyIdentifier))
189189
if err != nil {
190190
return fmt.Errorf("decoding certificate authority key id: %w", err)
191191
}

command/ota/generate.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,10 @@ func Generate(binFile string, outFile string, fqbn string) error {
6868

6969
return nil
7070
}
71+
72+
func dereferenceString(s *string) string {
73+
if s == nil {
74+
return ""
75+
}
76+
return *s
77+
}

command/ota/massupload.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ import (
2121
"context"
2222
"errors"
2323
"fmt"
24-
"github.com/sirupsen/logrus"
2524
"os"
2625
"path/filepath"
2726

27+
"github.com/sirupsen/logrus"
28+
2829
"github.com/arduino/arduino-cloud-cli/config"
2930
"github.com/arduino/arduino-cloud-cli/internal/iot"
3031
"github.com/arduino/arduino-cloud-cli/internal/ota"
@@ -179,8 +180,8 @@ func validateDevices(ctx context.Context, lister deviceLister, ids []string, fqb
179180
continue
180181
}
181182
// Device FQBN doesn't match the passed one
182-
if found.Fqbn != fqbn {
183-
inv := Result{ID: id, Err: fmt.Errorf("has FQBN '%s' instead of '%s'", found.Fqbn, fqbn)}
183+
if dereferenceString(found.Fqbn) != fqbn {
184+
inv := Result{ID: id, Err: fmt.Errorf("has FQBN '%s' instead of '%s'", dereferenceString(found.Fqbn), fqbn)}
184185
invalid = append(invalid, inv)
185186
continue
186187
}

command/ota/massupload_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ func TestValidateDevices(t *testing.T) {
9696

9797
mockDeviceList := deviceListerTest{
9898
list: []iotclient.ArduinoDevicev2{
99-
{Id: idCorrect1, Fqbn: correctFQBN},
100-
{Id: idCorrect2, Fqbn: correctFQBN},
101-
{Id: idNotValid, Fqbn: wrongFQBN},
99+
{Id: idCorrect1, Fqbn: &correctFQBN},
100+
{Id: idCorrect2, Fqbn: &correctFQBN},
101+
{Id: idNotValid, Fqbn: &wrongFQBN},
102102
},
103103
}
104104

0 commit comments

Comments
 (0)