Skip to content

Commit fbf12c2

Browse files
committed
Implemented programmers list command
1 parent c2c8cfd commit fbf12c2

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

cli/upload/upload.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ func (p *programmersList) Data() interface{} {
128128

129129
func (p *programmersList) String() string {
130130
t := table.New()
131-
t.SetHeader("Programmer Name", "ID", "Platform")
131+
t.SetHeader("ID", "Programmer Name", "Platform")
132132
for _, prog := range p.Programmers {
133-
t.AddRow(prog.GetName(), prog.GetId(), prog.GetPlatform())
133+
t.AddRow(prog.GetId(), prog.GetName(), prog.GetPlatform())
134134
}
135135
return t.Render()
136136
}

commands/upload/programmers_list.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 license@arduino.cc.
15+
16+
package upload
17+
18+
import (
19+
"context"
20+
"fmt"
21+
22+
"github.com/arduino/arduino-cli/arduino/cores"
23+
"github.com/arduino/arduino-cli/commands"
24+
rpc "github.com/arduino/arduino-cli/rpc/commands"
25+
)
26+
27+
// ListProgrammersAvailableForUpload FIXMEDOC
28+
func ListProgrammersAvailableForUpload(ctx context.Context, req *rpc.ListProgrammersAvailableForUploadReq) (*rpc.ListProgrammersAvailableForUploadResp, error) {
29+
pm := commands.GetPackageManager(req.GetInstance().GetId())
30+
31+
fqbnIn := req.GetFqbn()
32+
if fqbnIn == "" {
33+
return nil, fmt.Errorf("no Fully Qualified Board Name provided")
34+
}
35+
fqbn, err := cores.ParseFQBN(fqbnIn)
36+
if err != nil {
37+
return nil, fmt.Errorf("incorrect FQBN: %s", err)
38+
}
39+
40+
// Find target platforms
41+
_, platform, _, _, refPlatform, err := pm.ResolveFQBN(fqbn)
42+
if err != nil {
43+
return nil, fmt.Errorf("incorrect FQBN: %s", err)
44+
}
45+
46+
result := []*rpc.Programmer{}
47+
createRPCProgrammer := func(id string, programmer *cores.Programmer) *rpc.Programmer {
48+
return &rpc.Programmer{
49+
Id: id,
50+
Platform: programmer.PlatformRelease.String(),
51+
Name: programmer.Name,
52+
}
53+
}
54+
if refPlatform != platform {
55+
for id, programmer := range refPlatform.Programmers {
56+
result = append(result, createRPCProgrammer(id, programmer))
57+
}
58+
}
59+
for id, programmer := range platform.Programmers {
60+
result = append(result, createRPCProgrammer(id, programmer))
61+
}
62+
63+
return &rpc.ListProgrammersAvailableForUploadResp{
64+
Programmers: result,
65+
}, nil
66+
}

0 commit comments

Comments
 (0)