Skip to content

Commit 2855123

Browse files
committed
Added scaffolding for external programmer support
1 parent 8220b32 commit 2855123

File tree

6 files changed

+344
-88
lines changed

6 files changed

+344
-88
lines changed

cli/upload/upload.go

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,19 @@ import (
2424
"github.com/arduino/arduino-cli/cli/instance"
2525
"github.com/arduino/arduino-cli/commands/upload"
2626
rpc "github.com/arduino/arduino-cli/rpc/commands"
27+
"github.com/arduino/arduino-cli/table"
2728
"github.com/arduino/go-paths-helper"
2829
"github.com/sirupsen/logrus"
2930
"github.com/spf13/cobra"
3031
)
3132

3233
var (
33-
fqbn string
34-
port string
35-
verbose bool
36-
verify bool
37-
importDir string
34+
fqbn string
35+
port string
36+
verbose bool
37+
verify bool
38+
importDir string
39+
programmer string
3840
)
3941

4042
// NewCommand created a new `upload` command
@@ -53,6 +55,7 @@ func NewCommand() *cobra.Command {
5355
uploadCommand.Flags().StringVarP(&importDir, "input-dir", "", "", "Direcory containing binaries to upload.")
5456
uploadCommand.Flags().BoolVarP(&verify, "verify", "t", false, "Verify uploaded binary after the upload.")
5557
uploadCommand.Flags().BoolVarP(&verbose, "verbose", "v", false, "Optional, turns on verbose mode.")
58+
uploadCommand.Flags().StringVarP(&programmer, "programmer", "P", "", "Optional, use the specified programmer to upload or 'list' to list supported programmers.")
5659

5760
return uploadCommand
5861
}
@@ -64,6 +67,21 @@ func run(command *cobra.Command, args []string) {
6467
os.Exit(errorcodes.ErrGeneric)
6568
}
6669

70+
if programmer == "list" {
71+
resp, err := upload.ListProgrammersAvailableForUpload(context.Background(), &rpc.ListProgrammersAvailableForUploadReq{
72+
Instance: instance,
73+
Fqbn: fqbn,
74+
})
75+
if err != nil {
76+
feedback.Errorf("Error listing programmers: %v", err)
77+
os.Exit(errorcodes.ErrGeneric)
78+
}
79+
feedback.PrintResult(&programmersList{
80+
Programmers: resp.GetProgrammers(),
81+
})
82+
os.Exit(0)
83+
}
84+
6785
var path *paths.Path
6886
if len(args) > 0 {
6987
path = paths.New(args[0])
@@ -78,6 +96,7 @@ func run(command *cobra.Command, args []string) {
7896
Verbose: verbose,
7997
Verify: verify,
8098
ImportDir: importDir,
99+
Programmer: programmer,
81100
}, os.Stdout, os.Stderr); err != nil {
82101
feedback.Errorf("Error during Upload: %v", err)
83102
os.Exit(errorcodes.ErrGeneric)
@@ -98,3 +117,20 @@ func initSketchPath(sketchPath *paths.Path) *paths.Path {
98117
logrus.Infof("Reading sketch from dir: %s", wd)
99118
return wd
100119
}
120+
121+
type programmersList struct {
122+
Programmers []*rpc.Programmer
123+
}
124+
125+
func (p *programmersList) Data() interface{} {
126+
return p.Programmers
127+
}
128+
129+
func (p *programmersList) String() string {
130+
t := table.New()
131+
t.SetHeader("Programmer Name", "ID", "Platform")
132+
for _, prog := range p.Programmers {
133+
t.AddRow(prog.GetName(), prog.GetId(), prog.GetPlatform())
134+
}
135+
return t.Render()
136+
}

commands/daemon/daemon.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ func (s *ArduinoCoreServerImpl) Upload(req *rpc.UploadReq, stream rpc.ArduinoCor
216216
return stream.Send(resp)
217217
}
218218

219+
// ListProgrammersAvailableForUpload FIXMEDOC
220+
func (s *ArduinoCoreServerImpl) ListProgrammersAvailableForUpload(ctx context.Context, req *rpc.ListProgrammersAvailableForUploadReq) (*rpc.ListProgrammersAvailableForUploadResp, error) {
221+
return upload.ListProgrammersAvailableForUpload(ctx, req)
222+
}
223+
219224
// LibraryDownload FIXMEDOC
220225
func (s *ArduinoCoreServerImpl) LibraryDownload(req *rpc.LibraryDownloadReq, stream rpc.ArduinoCore_LibraryDownloadServer) error {
221226
resp, err := lib.LibraryDownload(

rpc/commands/commands.pb.go

Lines changed: 99 additions & 61 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rpc/commands/commands.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ service ArduinoCore {
8585
// Upload a compiled sketch to an Arduino board.
8686
rpc Upload(UploadReq) returns (stream UploadResp);
8787

88+
rpc ListProgrammersAvailableForUpload(ListProgrammersAvailableForUploadReq) returns (ListProgrammersAvailableForUploadResp);
89+
8890
// Search for a platform in the platforms indexes.
8991
rpc PlatformSearch(PlatformSearchReq) returns (PlatformSearchResp);
9092

0 commit comments

Comments
 (0)