Skip to content

Commit dfb05c9

Browse files
author
Massimiliano Pippi
committed
make board listall format agnostic
1 parent ff42ff2 commit dfb05c9

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

cli/board/listall.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424

2525
"github.com/arduino/arduino-cli/cli/errorcodes"
2626
"github.com/arduino/arduino-cli/cli/feedback"
27-
"github.com/arduino/arduino-cli/cli/globals"
2827
"github.com/arduino/arduino-cli/cli/instance"
2928
"github.com/arduino/arduino-cli/commands/board"
3029
rpc "github.com/arduino/arduino-cli/rpc/commands"
@@ -58,22 +57,28 @@ func runListAllCommand(cmd *cobra.Command, args []string) {
5857
os.Exit(errorcodes.ErrGeneric)
5958
}
6059

61-
if globals.OutputFormat == "json" {
62-
feedback.PrintJSON(list)
63-
} else {
64-
outputBoardListAll(list)
65-
}
60+
feedback.PrintResult(resultAll{list})
61+
}
62+
63+
// ouput from this command requires special formatting, let's create a dedicated
64+
// feedback.Result implementation
65+
type resultAll struct {
66+
list *rpc.BoardListAllResp
67+
}
68+
69+
func (dr resultAll) Data() interface{} {
70+
return dr.list
6671
}
6772

68-
func outputBoardListAll(list *rpc.BoardListAllResp) {
69-
sort.Slice(list.Boards, func(i, j int) bool {
70-
return list.Boards[i].GetName() < list.Boards[j].GetName()
73+
func (dr resultAll) String() string {
74+
sort.Slice(dr.list.Boards, func(i, j int) bool {
75+
return dr.list.Boards[i].GetName() < dr.list.Boards[j].GetName()
7176
})
7277

7378
t := table.New()
7479
t.SetHeader("Board Name", "FQBN")
75-
for _, item := range list.GetBoards() {
80+
for _, item := range dr.list.GetBoards() {
7681
t.AddRow(item.GetName(), item.GetFQBN())
7782
}
78-
feedback.Print(t.Render())
83+
return t.Render()
7984
}

0 commit comments

Comments
 (0)