Skip to content

Commit 96139c2

Browse files
committed
Fixing arduino sketch sync command.
1 parent 02e09a5 commit 96139c2

File tree

5 files changed

+33
-27
lines changed

5 files changed

+33
-27
lines changed

commands/login/login.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"io/ioutil"
3535
"os"
3636
"path/filepath"
37+
"strings"
3738
"syscall"
3839

3940
"github.com/bcmi-labs/arduino-cli/auth"
@@ -87,6 +88,8 @@ func run(cmd *cobra.Command, args []string) {
8788
} else {
8889
user = args[0]
8990
}
91+
// Username is always lowercase.
92+
user = strings.ToLower(user)
9093

9194
if passwordEmpty {
9295
fmt.Print("Password: ")

commands/sketch/sync.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ func runSyncCommand(cmd *cobra.Command, args []string) {
250250
result.SkippedSketches = append(result.SkippedSketches, item.Name)
251251
}
252252
} else { // Only local, push.
253-
logrus.Info("No conflict, pushing `%s` as new sketch", item.Name)
253+
logrus.Infof("No conflict, pushing `%s` as new sketch", item.Name)
254254
err := pushSketch(*item, sketchbook, bearerToken)
255255
if err != nil {
256256
logrus.WithError(err).Warnf("Cannot push `%s`", item.Name)
@@ -265,8 +265,7 @@ func runSyncCommand(cmd *cobra.Command, args []string) {
265265
}
266266
}
267267
for _, item := range onlineSketches.Sketches {
268-
_, hasConflict := onlineSketchesMap[*item.Name]
269-
if hasConflict {
268+
if sketchMap[*item.Name] != nil {
270269
continue
271270
}
272271
// Only online, pull.

create_client_helpers/sketches.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ func (c *Client) NewSearchSketchesRequest(ctx context.Context, path string, offs
209209
}
210210
header := req.Header
211211
if authorization != nil {
212-
213212
header.Set("Authorization", *authorization)
214213
}
215214
return req, nil

create_client_helpers/user_types.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,26 @@ import (
3737
"github.com/bcmi-labs/arduino-modules/sketches"
3838
)
3939

40-
// A file saved on the virtual filesystem
40+
// File is a file saved on the virtual filesystem.
4141
type File struct {
42-
// The contents of the file, encoded in base64
42+
// The contents of the file, encoded in base64.
4343
Data *string `form:"data,omitempty" json:"data,omitempty" xml:"data,omitempty"`
44-
// The name of the file
44+
// The name of the file.
4545
Name string `form:"name" json:"name" xml:"name"`
4646
}
4747

48-
// A program meant to be uploaded onto a board
48+
// Sketch is a program meant to be uploaded onto a board.
4949
type Sketch struct {
50-
// The name of the sketch
50+
// The name of the sketch.
5151
Name string `form:"name" json:"name" xml:"name"`
52-
// The other files contained in the sketch
52+
// The other files contained in the sketch.
5353
Files []*File `form:"files,omitempty" json:"files,omitempty" xml:"files,omitempty"`
54-
// The folder path where the sketch is saved
54+
// The folder path where the sketch is saved.
5555
Folder *string `form:"folder,omitempty" json:"folder,omitempty" xml:"folder,omitempty"`
56-
// The main file of the sketch
56+
// The main file of the sketch.
5757
Ino *File `form:"ino" json:"ino" xml:"ino"`
5858
Metadata *SketchMetadata `form:"metadata,omitempty" json:"metadata,omitempty" xml:"metadata,omitempty"`
59-
// The username of the owner of the sketch
59+
// The username of the owner of the sketch.
6060
Owner *string `form:"owner,omitempty" json:"owner,omitempty" xml:"owner,omitempty"`
6161
// A private sketch is only visible to its owner.
6262
Private bool `form:"private" json:"private" xml:"private"`
@@ -87,9 +87,8 @@ func ConvertFrom(sketch sketches.Sketch) *Sketch {
8787
Types: sketch.Types,
8888
Metadata: ConvertMetadataFrom(sketch.Metadata),
8989
}
90-
ret.Files = make([]*File, len(sketch.Files))
91-
for i, f := range sketch.Files {
92-
if f.Name == "sketch.json" { //skipping sketch.json file, since it is Metadata of the sketch
90+
for _, f := range sketch.Files {
91+
if f.Name == "sketch.json" { // Skipping sketch.json file, since it is Metadata of the sketch.
9392
continue
9493
}
9594
_, filePath := filepath.Split(f.Path)
@@ -99,10 +98,10 @@ func ConvertFrom(sketch sketches.Sketch) *Sketch {
9998
}
10099

101100
data := base64.StdEncoding.EncodeToString(content)
102-
ret.Files[i] = &File{
101+
ret.Files = append(ret.Files, &File{
103102
Data: &data,
104103
Name: f.Name,
105-
}
104+
})
106105
}
107106
return &ret
108107
}
@@ -113,6 +112,7 @@ type SketchMetadata struct {
113112
IncludedLibs []*SketchMetadataLib `form:"included_libs,omitempty" json:"included_libs,omitempty" xml:"included_libs,omitempty"`
114113
}
115114

115+
// ConvertMetadataFrom creates SketchMetadata object from sketches.Metadata.
116116
func ConvertMetadataFrom(metadata *sketches.Metadata) *SketchMetadata {
117117
if metadata == nil {
118118
return nil
@@ -137,22 +137,22 @@ func ConvertMetadataFrom(metadata *sketches.Metadata) *SketchMetadata {
137137
return &ret
138138
}
139139

140-
// The board associated with the sketch
140+
// SketchMetadataCPU is the board associated with the sketch.
141141
type SketchMetadataCPU struct {
142-
// The fqbn of the board
142+
// The fqbn of the board.
143143
Fqbn *string `form:"fqbn,omitempty" json:"fqbn,omitempty" xml:"fqbn,omitempty"`
144-
// The name of the board
144+
// The name of the board.
145145
Name *string `form:"name,omitempty" json:"name,omitempty" xml:"name,omitempty"`
146-
// Requires an upload via network
146+
// Requires an upload via network.
147147
Network *bool `form:"network,omitempty" json:"network,omitempty" xml:"network,omitempty"`
148-
// The port of the board
148+
// The port of the board.
149149
Port *string `form:"port,omitempty" json:"port,omitempty" xml:"port,omitempty"`
150150
}
151151

152-
// A library associated with the sketch
152+
// SketchMetadataLib is a library associated with the sketch.
153153
type SketchMetadataLib struct {
154-
// The name of the library
154+
// The name of the library.
155155
Name *string `form:"name,omitempty" json:"name,omitempty" xml:"name,omitempty"`
156-
// The version of the library
156+
// The version of the library.
157157
Version *string `form:"version,omitempty" json:"version,omitempty" xml:"version,omitempty"`
158158
}

vendor/github.com/bcmi-labs/arduino-modules/sketches/sketches.go

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)