Skip to content

Commit

Permalink
refactor PrintUsedLibrariesIfVerbose in a function
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-perugini committed Sep 8, 2023
1 parent fc9d011 commit 8d6c6d3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
6 changes: 5 additions & 1 deletion legacy/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,11 @@ func (s *Builder) Run(ctx *types.Context) error {
return nil
}),

&PrintUsedLibrariesIfVerbose{},
types.BareCommand(func(ctx *types.Context) error {
infoOut, _ := PrintUsedLibrariesIfVerbose(ctx.Verbose, ctx.SketchLibrariesDetector.ImportedLibraries())
ctx.Info(string(infoOut))
return nil
}),

&ExportProjectCMake{SketchError: mainErr != nil},

Expand Down
20 changes: 10 additions & 10 deletions legacy/builder/print_used_libraries_if_verbose.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,31 @@
package builder

import (
"bytes"
"time"

"github.com/arduino/arduino-cli/legacy/builder/types"
"github.com/arduino/arduino-cli/arduino/libraries"
)

type PrintUsedLibrariesIfVerbose struct{}

func (s *PrintUsedLibrariesIfVerbose) Run(ctx *types.Context) error {
if !ctx.Verbose || len(ctx.SketchLibrariesDetector.ImportedLibraries()) == 0 {
return nil
func PrintUsedLibrariesIfVerbose(verbose bool, importedLibraries libraries.List) ([]byte, error) {
if !verbose || len(importedLibraries) == 0 {
return nil, nil
}

for _, library := range ctx.SketchLibrariesDetector.ImportedLibraries() {
infoBuf := &bytes.Buffer{}
for _, library := range importedLibraries {
legacy := ""
if library.IsLegacy {
legacy = tr("(legacy)")
}
if library.Version.String() == "" {
ctx.Info(
infoBuf.WriteString(
tr("Using library %[1]s in folder: %[2]s %[3]s",
library.Name,
library.InstallDir,
legacy))
} else {
ctx.Info(
infoBuf.WriteString(
tr("Using library %[1]s at version %[2]s in folder: %[3]s %[4]s",
library.Name,
library.Version,
Expand All @@ -50,5 +50,5 @@ func (s *PrintUsedLibrariesIfVerbose) Run(ctx *types.Context) error {
}

time.Sleep(100 * time.Millisecond)
return nil
return infoBuf.Bytes(), nil
}

0 comments on commit 8d6c6d3

Please sign in to comment.