Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1a9066d

Browse files
committedAug 24, 2020
Sort examples results by name
1 parent a5d40b0 commit 1a9066d

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed
 

‎cli/lib/examples.go

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package lib
1818
import (
1919
"fmt"
2020
"os"
21+
"sort"
2122
"strings"
2223

2324
"github.com/arduino/arduino-cli/cli/errorcodes"
@@ -91,6 +92,10 @@ func (ir libraryExamplesResult) String() string {
9192
return "No libraries found."
9293
}
9394

95+
sort.Slice(ir.Examples, func(i, j int) bool {
96+
return strings.ToLower(ir.Examples[i].Library.Name) < strings.ToLower(ir.Examples[j].Library.Name)
97+
})
98+
9499
res := []string{}
95100
for _, lib := range ir.Examples {
96101
name := lib.Library.Name
@@ -100,6 +105,9 @@ func (ir libraryExamplesResult) String() string {
100105
name += " (" + lib.Library.GetLocation().String() + ")"
101106
}
102107
r := fmt.Sprintf("Examples for library %s\n", color.GreenString("%s", name))
108+
sort.Slice(lib.Examples, func(i, j int) bool {
109+
return strings.ToLower(lib.Examples[i]) < strings.ToLower(lib.Examples[j])
110+
})
103111
for _, example := range lib.Examples {
104112
examplePath := paths.New(example)
105113
r += fmt.Sprintf(" - %s%s\n",

0 commit comments

Comments
 (0)
Please sign in to comment.