Skip to content

Commit a23b32e

Browse files
author
Massimiliano Pippi
committed
make lib list format agnostic
1 parent dfb05c9 commit a23b32e

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

cli/lib/list.go

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
"github.com/arduino/arduino-cli/cli/errorcodes"
2424
"github.com/arduino/arduino-cli/cli/feedback"
25-
"github.com/arduino/arduino-cli/cli/globals"
2625
"github.com/arduino/arduino-cli/cli/instance"
2726
"github.com/arduino/arduino-cli/commands/lib"
2827
rpc "github.com/arduino/arduino-cli/rpc/commands"
@@ -66,27 +65,31 @@ func runListCommand(cmd *cobra.Command, args []string) {
6665
}
6766

6867
libs := res.GetInstalledLibrary()
69-
if libs != nil {
70-
if globals.OutputFormat == "json" {
71-
feedback.PrintJSON(libs)
72-
} else {
73-
outputListLibrary(libs)
74-
}
75-
}
68+
feedback.PrintResult(installedResult{libs})
7669

7770
logrus.Info("Done")
7871
}
7972

80-
func outputListLibrary(il []*rpc.InstalledLibrary) {
81-
if il == nil || len(il) == 0 {
82-
return
73+
// ouput from this command requires special formatting, let's create a dedicated
74+
// feedback.Result implementation
75+
type installedResult struct {
76+
installedLibs []*rpc.InstalledLibrary
77+
}
78+
79+
func (ir installedResult) Data() interface{} {
80+
return ir.installedLibs
81+
}
82+
83+
func (ir installedResult) String() string {
84+
if ir.installedLibs == nil || len(ir.installedLibs) == 0 {
85+
return ""
8386
}
8487

8588
t := table.New()
8689
t.SetHeader("Name", "Installed", "Available", "Location")
8790

8891
lastName := ""
89-
for _, libMeta := range il {
92+
for _, libMeta := range ir.installedLibs {
9093
lib := libMeta.GetLibrary()
9194
name := lib.Name
9295
if name == lastName {
@@ -110,5 +113,5 @@ func outputListLibrary(il []*rpc.InstalledLibrary) {
110113
}
111114
}
112115

113-
feedback.Print(t.Render())
116+
return t.Render()
114117
}

0 commit comments

Comments
 (0)