Skip to content

Added 'lib examples' command #905

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 9 commits into from
Aug 31, 2020
Merged
Prev Previous commit
Next Next commit
Sort examples results by name
  • Loading branch information
cmaglie committed Aug 24, 2020
commit 1a9066dc9ce5b3e39ce491cf9b7d18b97b4ef25c
8 changes: 8 additions & 0 deletions cli/lib/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package lib
import (
"fmt"
"os"
"sort"
"strings"

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

sort.Slice(ir.Examples, func(i, j int) bool {
return strings.ToLower(ir.Examples[i].Library.Name) < strings.ToLower(ir.Examples[j].Library.Name)
})

res := []string{}
for _, lib := range ir.Examples {
name := lib.Library.Name
Expand All @@ -100,6 +105,9 @@ func (ir libraryExamplesResult) String() string {
name += " (" + lib.Library.GetLocation().String() + ")"
}
r := fmt.Sprintf("Examples for library %s\n", color.GreenString("%s", name))
sort.Slice(lib.Examples, func(i, j int) bool {
return strings.ToLower(lib.Examples[i]) < strings.ToLower(lib.Examples[j])
})
for _, example := range lib.Examples {
examplePath := paths.New(example)
r += fmt.Sprintf(" - %s%s\n",
Expand Down