Skip to content

Commit 9d189f8

Browse files
committed
fix arduino-cli outdated --format json output
1 parent aba6a78 commit 9d189f8

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

cli/outdated/outdated.go

+28-14
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,39 @@ func runOutdatedCommand(cmd *cobra.Command, args []string) {
5757
feedback.Errorf(tr("Error retrieving outdated cores and libraries: %v"), err)
5858
}
5959

60+
feedback.PrintResult(outdatedResult{
61+
Platforms: outdatedResp.OutdatedPlatforms,
62+
Libraries: outdatedResp.OutdatedLibraries})
63+
}
64+
65+
// output from this command requires special formatting, let's create a dedicated
66+
// feedback.Result implementation
67+
type outdatedResult struct {
68+
Platforms []*rpc.Platform
69+
Libraries []*rpc.InstalledLibrary
70+
}
71+
72+
func (or outdatedResult) Data() interface{} {
73+
return or
74+
}
75+
76+
func (or outdatedResult) String() string {
6077
// Prints outdated cores
61-
tab := table.New()
62-
tab.SetHeader(tr("ID"), tr("Installed version"), tr("New version"), tr("Name"))
63-
if len(outdatedResp.OutdatedPlatforms) > 0 {
64-
for _, p := range outdatedResp.OutdatedPlatforms {
65-
tab.AddRow(p.Id, p.Installed, p.Latest, p.Name)
78+
t1 := table.New()
79+
t1.SetHeader(tr("ID"), tr("Installed version"), tr("New version"), tr("Name"))
80+
if len(or.Platforms) > 0 {
81+
for _, p := range or.Platforms {
82+
t1.AddRow(p.Id, p.Installed, p.Latest, p.Name)
6683
}
67-
feedback.Print(tab.Render())
6884
}
6985

7086
// Prints outdated libraries
71-
tab = table.New()
72-
tab.SetHeader(tr("Library name"), tr("Installed version"), tr("New version"))
73-
if len(outdatedResp.OutdatedLibraries) > 0 {
74-
for _, l := range outdatedResp.OutdatedLibraries {
75-
tab.AddRow(l.Library.Name, l.Library.Version, l.Release.Version)
87+
t2 := table.New()
88+
t2.SetHeader(tr("Library name"), tr("Installed version"), tr("New version"))
89+
if len(or.Libraries) > 0 {
90+
for _, l := range or.Libraries {
91+
t2.AddRow(l.Library.Name, l.Library.Version, l.Release.Version)
7692
}
77-
feedback.Print(tab.Render())
7893
}
79-
80-
logrus.Info("Done")
94+
return t1.Render() + "\n" + t2.Render()
8195
}

0 commit comments

Comments
 (0)