Skip to content

Commit

Permalink
now 'board listall' command accept search params
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Oct 9, 2018
1 parent 98fec8b commit 5ba319d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,13 @@ arduino:samd 1.6.19 Arduino SAMD Boards (32-bits ARM Cortex-M0+)

once the core is determined you should install it with `arduino-cli core install arduino:samd` and, once installed, you can connect the board and detect it with `arduino-cli board list`.

If the board is not detected for any reason, you can list all the supported boards with `arduino-cli board listall`
If the board is not detected for any reason, you can list all the supported boards with `arduino-cli board listall` and also search for a specific board, in our example `arduino-cli board listall zero`.

```
$ arduino-cli board listall zero
Board Name FQBN
Arduino MKRZERO arduino:samd:mkrzero
Arduino/Genuino Zero (Native USB Port) arduino:samd:arduino_zero_native
Arduino/Genuino Zero (Programming Port) arduino:samd:arduino_zero_edbg
```

30 changes: 24 additions & 6 deletions commands/board/listall.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package board

import (
"sort"
"strings"

"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/common/formatter"
Expand All @@ -28,12 +29,16 @@ import (

func initListAllCommand() *cobra.Command {
listAllCommand := &cobra.Command{
Use: "listall",
Short: "List all known boards.",
Long: "List all boards that have the support platform installed.",
Example: " " + commands.AppName + " board listall",
Args: cobra.NoArgs,
Run: runListAllCommand,
Use: "listall [boardname]",
Short: "List all known boards and their corresponding FQBN.",
Long: "" +
"List all boards that have the support platform installed. You can search\n" +
"for a specific board if you specify the board name",
Example: "" +
" " + commands.AppName + " board listall\n" +
" " + commands.AppName + " board listall zero",
Args: cobra.ArbitraryArgs,
Run: runListAllCommand,
}
return listAllCommand
}
Expand All @@ -42,6 +47,16 @@ func initListAllCommand() *cobra.Command {
func runListAllCommand(cmd *cobra.Command, args []string) {
pm := commands.InitPackageManager()

match := func(name string) bool {
name = strings.ToLower(name)
for _, term := range args {
if !strings.Contains(name, strings.ToLower(term)) {
return false
}
}
return true
}

list := &output.BoardList{}
for _, targetPackage := range pm.GetPackages().Packages {
for _, platform := range targetPackage.Platforms {
Expand All @@ -50,6 +65,9 @@ func runListAllCommand(cmd *cobra.Command, args []string) {
continue
}
for _, board := range platformRelease.Boards {
if !match(board.Name()) {
continue
}
list.Boards = append(list.Boards, &output.BoardListItem{
Name: board.Name(),
Fqbn: board.FQBN(),
Expand Down

0 comments on commit 5ba319d

Please sign in to comment.