Skip to content

Commit 0d38852

Browse files
committed
Moved LoadSketch command in the proper place
1 parent 399d727 commit 0d38852

File tree

3 files changed

+58
-33
lines changed

3 files changed

+58
-33
lines changed

Diff for: commands/daemon/daemon.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ func (s *ArduinoCoreServerImpl) NewSketch(ctx context.Context, req *rpc.NewSketc
198198

199199
// LoadSketch FIXMEDOC
200200
func (s *ArduinoCoreServerImpl) LoadSketch(ctx context.Context, req *rpc.LoadSketchRequest) (*rpc.LoadSketchResponse, error) {
201-
resp, err := commands.LoadSketch(ctx, req)
201+
resp, err := sketch.LoadSketch(ctx, req)
202202
return resp, convertErrorToRPCStatus(err)
203203
}
204204

Diff for: commands/instances.go

-32
Original file line numberDiff line numberDiff line change
@@ -569,38 +569,6 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexRequest, downloadCB rp
569569
return nil
570570
}
571571

572-
// LoadSketch collects and returns all files composing a sketch
573-
func LoadSketch(ctx context.Context, req *rpc.LoadSketchRequest) (*rpc.LoadSketchResponse, error) {
574-
// TODO: This should be a ToRpc function for the Sketch struct
575-
sk, err := sketch.New(paths.New(req.SketchPath))
576-
if err != nil {
577-
return nil, &arduino.CantOpenSketchError{Cause: err}
578-
}
579-
580-
otherSketchFiles := make([]string, sk.OtherSketchFiles.Len())
581-
for i, file := range sk.OtherSketchFiles {
582-
otherSketchFiles[i] = file.String()
583-
}
584-
585-
additionalFiles := make([]string, sk.AdditionalFiles.Len())
586-
for i, file := range sk.AdditionalFiles {
587-
additionalFiles[i] = file.String()
588-
}
589-
590-
rootFolderFiles := make([]string, sk.RootFolderFiles.Len())
591-
for i, file := range sk.RootFolderFiles {
592-
rootFolderFiles[i] = file.String()
593-
}
594-
595-
return &rpc.LoadSketchResponse{
596-
MainFile: sk.MainFile.String(),
597-
LocationPath: sk.FullPath.String(),
598-
OtherSketchFiles: otherSketchFiles,
599-
AdditionalFiles: additionalFiles,
600-
RootFolderFiles: rootFolderFiles,
601-
}, nil
602-
}
603-
604572
// firstUpdate downloads libraries and packages indexes if they don't exist.
605573
// This ideally is only executed the first time the CLI is run.
606574
func firstUpdate(ctx context.Context, instance *rpc.Instance, downloadCb func(msg *rpc.DownloadProgress), externalPackageIndexes []*url.URL) error {

Diff for: commands/sketch/load.go

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// This file is part of arduino-cli.
2+
//
3+
// Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4+
//
5+
// This software is released under the GNU General Public License version 3,
6+
// which covers the main part of arduino-cli.
7+
// The terms of this license can be found at:
8+
// https://www.gnu.org/licenses/gpl-3.0.en.html
9+
//
10+
// You can be released from the requirements of the above licenses by purchasing
11+
// a commercial license. Buying such a license is mandatory if you want to
12+
// modify or otherwise use the software for commercial activities involving the
13+
// Arduino software without disclosing the source code of your own applications.
14+
// To purchase a commercial license, send an email to [email protected].
15+
16+
package sketch
17+
18+
import (
19+
"context"
20+
21+
"github.com/arduino/arduino-cli/arduino"
22+
"github.com/arduino/arduino-cli/arduino/sketch"
23+
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
24+
paths "github.com/arduino/go-paths-helper"
25+
)
26+
27+
// LoadSketch collects and returns all files composing a sketch
28+
func LoadSketch(ctx context.Context, req *rpc.LoadSketchRequest) (*rpc.LoadSketchResponse, error) {
29+
// TODO: This should be a ToRpc function for the Sketch struct
30+
sk, err := sketch.New(paths.New(req.SketchPath))
31+
if err != nil {
32+
return nil, &arduino.CantOpenSketchError{Cause: err}
33+
}
34+
35+
otherSketchFiles := make([]string, sk.OtherSketchFiles.Len())
36+
for i, file := range sk.OtherSketchFiles {
37+
otherSketchFiles[i] = file.String()
38+
}
39+
40+
additionalFiles := make([]string, sk.AdditionalFiles.Len())
41+
for i, file := range sk.AdditionalFiles {
42+
additionalFiles[i] = file.String()
43+
}
44+
45+
rootFolderFiles := make([]string, sk.RootFolderFiles.Len())
46+
for i, file := range sk.RootFolderFiles {
47+
rootFolderFiles[i] = file.String()
48+
}
49+
50+
return &rpc.LoadSketchResponse{
51+
MainFile: sk.MainFile.String(),
52+
LocationPath: sk.FullPath.String(),
53+
OtherSketchFiles: otherSketchFiles,
54+
AdditionalFiles: additionalFiles,
55+
RootFolderFiles: rootFolderFiles,
56+
}, nil
57+
}

0 commit comments

Comments
 (0)