Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
arduino-cli
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Operations
Operations
Metrics
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
arduino-cli
Commits
38a0dfd5
Unverified
Commit
38a0dfd5
authored
Jan 04, 2023
by
Luca Bianconi
Committed by
GitHub
Jan 04, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: consistent boards list ordering across output formats (#2025)
parent
50918b49
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
4 deletions
+45
-4
commands/board/listall.go
commands/board/listall.go
+38
-2
internal/integrationtest/board/board_test.go
internal/integrationtest/board/board_test.go
+7
-2
No files found.
commands/board/listall.go
View file @
38a0dfd5
...
...
@@ -17,9 +17,11 @@ package board
import
(
"context"
"sort"
"strings"
"github.com/arduino/arduino-cli/arduino"
"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/arduino/utils"
"github.com/arduino/arduino-cli/commands"
rpc
"github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
...
...
@@ -36,8 +38,8 @@ func ListAll(ctx context.Context, req *rpc.BoardListAllRequest) (*rpc.BoardListA
searchArgs
:=
strings
.
Join
(
req
.
GetSearchArgs
(),
" "
)
list
:=
&
rpc
.
BoardListAllResponse
{
Boards
:
[]
*
rpc
.
BoardListItem
{}}
for
_
,
targetPackage
:=
range
pme
.
GetPackages
(
)
{
for
_
,
platform
:=
range
t
argetPackage
.
Platforms
{
for
_
,
targetPackage
:=
range
toSortedPackageArray
(
pme
.
GetPackages
()
)
{
for
_
,
platform
:=
range
t
oSortedPlatformArray
(
targetPackage
.
Platforms
)
{
installedPlatformRelease
:=
pme
.
GetInstalledPlatformRelease
(
platform
)
// We only want to list boards for installed platforms
if
installedPlatformRelease
==
nil
{
...
...
@@ -93,3 +95,37 @@ func ListAll(ctx context.Context, req *rpc.BoardListAllRequest) (*rpc.BoardListA
return
list
,
nil
}
// TODO use a generic function instead of the two below once go >1.18 is adopted.
// Without generics we either have to create multiple functions for different map types
// or resort to type assertions on the caller side
// toSortedPackageArray takes a packages map and returns its values as array
// ordered by the map keys alphabetically
func
toSortedPackageArray
(
sourceMap
cores
.
Packages
)
[]
*
cores
.
Package
{
keys
:=
[]
string
{}
for
key
:=
range
sourceMap
{
keys
=
append
(
keys
,
key
)
}
sort
.
Strings
(
keys
)
sortedValues
:=
make
([]
*
cores
.
Package
,
len
(
keys
))
for
i
,
key
:=
range
keys
{
sortedValues
[
i
]
=
sourceMap
[
key
]
}
return
sortedValues
}
// toSortedPlatformArray takes a packages map and returns its values as array
// ordered by the map keys alphabetically
func
toSortedPlatformArray
(
sourceMap
map
[
string
]
*
cores
.
Platform
)
[]
*
cores
.
Platform
{
keys
:=
[]
string
{}
for
key
:=
range
sourceMap
{
keys
=
append
(
keys
,
key
)
}
sort
.
Strings
(
keys
)
sortedValues
:=
make
([]
*
cores
.
Platform
,
len
(
keys
))
for
i
,
key
:=
range
keys
{
sortedValues
[
i
]
=
sourceMap
[
key
]
}
return
sortedValues
}
internal/integrationtest/board/board_test.go
View file @
38a0dfd5
...
...
@@ -33,7 +33,10 @@ func TestCorrectBoardListOrdering(t *testing.T) {
env
,
cli
:=
integrationtest
.
CreateArduinoCLIWithEnvironment
(
t
)
defer
env
.
CleanUp
()
_
,
_
,
err
:=
cli
.
Run
(
"core"
,
"install"
,
"arduino:avr"
)
// install two cores, boards must be ordered by package name and platform name
_
,
_
,
err
:=
cli
.
Run
(
"core"
,
"install"
,
"arduino:sam"
)
require
.
NoError
(
t
,
err
)
_
,
_
,
err
=
cli
.
Run
(
"core"
,
"install"
,
"arduino:avr"
)
require
.
NoError
(
t
,
err
)
jsonOut
,
_
,
err
:=
cli
.
Run
(
"board"
,
"listall"
,
"--format"
,
"json"
)
require
.
NoError
(
t
,
err
)
...
...
@@ -64,7 +67,9 @@ func TestCorrectBoardListOrdering(t *testing.T) {
"arduino:avr:yunmini",
"arduino:avr:chiwawa",
"arduino:avr:one",
"arduino:avr:unowifi"
"arduino:avr:unowifi",
"arduino:sam:arduino_due_x_dbg",
"arduino:sam:arduino_due_x"
]`
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment