Skip to content

Added support for hidden boards in 'board listall' command #939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions arduino/cores/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ func (b *Board) FQBN() string {
return platform.Package.Name + ":" + platform.Architecture + ":" + b.BoardID
}

// IsHidden returns true if the board is marked as hidden in the platform
func (b *Board) IsHidden() bool {
return b.Properties.GetBoolean("hide")
}

func (b *Board) String() string {
return b.FQBN()
}
Expand Down
16 changes: 12 additions & 4 deletions cli/board/listall.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ func initListAllCommand() *cobra.Command {
Args: cobra.ArbitraryArgs,
Run: runListAllCommand,
}
listAllCommand.Flags().BoolVarP(&showHiddenBoard, "show-hidden", "a", false, "Show also boards marked as 'hidden' in the platform")
return listAllCommand
}

var showHiddenBoard bool

// runListAllCommand list all installed boards
func runListAllCommand(cmd *cobra.Command, args []string) {
inst, err := instance.CreateInstance()
Expand All @@ -54,8 +57,9 @@ func runListAllCommand(cmd *cobra.Command, args []string) {
}

list, err := board.ListAll(context.Background(), &rpc.BoardListAllReq{
Instance: inst,
SearchArgs: args,
Instance: inst,
SearchArgs: args,
IncludeHiddenBoards: showHiddenBoard,
})
if err != nil {
feedback.Errorf("Error listing boards: %v", err)
Expand All @@ -81,9 +85,13 @@ func (dr resultAll) String() string {
})

t := table.New()
t.SetHeader("Board Name", "FQBN")
t.SetHeader("Board Name", "FQBN", "")
for _, item := range dr.list.GetBoards() {
t.AddRow(item.GetName(), item.GetFQBN())
hidden := ""
if item.IsHidden {
hidden = "(hidden)"
}
t.AddRow(item.GetName(), item.GetFQBN(), hidden)
}
return t.Render()
}
8 changes: 6 additions & 2 deletions commands/board/listall.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,13 @@ func ListAll(ctx context.Context, req *rpc.BoardListAllReq) (*rpc.BoardListAllRe
if !match(board.Name()) {
continue
}
if !req.GetIncludeHiddenBoards() && board.IsHidden() {
continue
}
list.Boards = append(list.Boards, &rpc.BoardListItem{
Name: board.Name(),
FQBN: board.FQBN(),
Name: board.Name(),
FQBN: board.FQBN(),
IsHidden: board.IsHidden(),
})
}
}
Expand Down
64 changes: 44 additions & 20 deletions rpc/commands/board.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions rpc/commands/board.proto
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ message BoardListAllReq {
Instance instance = 1;
// The search query to filter the board list by.
repeated string search_args = 2;
// Set to true to get also the boards marked as "hidden" in the platform
bool include_hidden_boards = 3;
}

message BoardListAllResp {
Expand All @@ -209,4 +211,6 @@ message BoardListItem {
string name = 1;
// The fully qualified board name. Used to identify the board to a machine.
string FQBN = 2;
// If the board is marked as "hidden" in the platform
bool is_hidden = 3;
}
11 changes: 11 additions & 0 deletions test/test_board.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,17 @@ def test_board_details(run_command):
# Download samd core pinned to 1.8.6
result = run_command("core install arduino:[email protected]")
assert result.ok

# Test board listall with and without showing hidden elements
result = run_command("board listall MIPS --format json")
assert result.ok
assert result.stdout == "{}"

result = run_command("board listall MIPS -a --format json")
assert result.ok
result = json.loads(result.stdout)
assert result["boards"][0]["name"] == "Arduino Tian (MIPS Console port)"

result = run_command("board details -b arduino:samd:nano_33_iot --format json")
assert result.ok
# Sort everything before compare
Expand Down