Unverified Commit 4d31f4fd authored by Umberto Baldi's avatar Umberto Baldi Committed by GitHub

fix `arduino-cli outdated --format json` output (#1746)

parent 0a1d8eed
......@@ -57,25 +57,42 @@ func runOutdatedCommand(cmd *cobra.Command, args []string) {
feedback.Errorf(tr("Error retrieving outdated cores and libraries: %v"), err)
}
feedback.PrintResult(outdatedResult{
Platforms: outdatedResp.OutdatedPlatforms,
Libraries: outdatedResp.OutdatedLibraries})
}
// output from this command requires special formatting, let's create a dedicated
// feedback.Result implementation
type outdatedResult struct {
Platforms []*rpc.Platform
Libraries []*rpc.InstalledLibrary
}
func (or outdatedResult) Data() interface{} {
return or
}
func (or outdatedResult) String() string {
// Prints outdated cores
tab := table.New()
tab.SetHeader(tr("ID"), tr("Installed version"), tr("New version"), tr("Name"))
if len(outdatedResp.OutdatedPlatforms) > 0 {
for _, p := range outdatedResp.OutdatedPlatforms {
tab.AddRow(p.Id, p.Installed, p.Latest, p.Name)
t1 := table.New()
if len(or.Platforms) > 0 {
t1.SetHeader(tr("ID"), tr("Installed version"), tr("New version"), tr("Name"))
for _, p := range or.Platforms {
t1.AddRow(p.Id, p.Installed, p.Latest, p.Name)
}
feedback.Print(tab.Render())
}
// Prints outdated libraries
tab = table.New()
tab.SetHeader(tr("Library name"), tr("Installed version"), tr("New version"))
if len(outdatedResp.OutdatedLibraries) > 0 {
for _, l := range outdatedResp.OutdatedLibraries {
tab.AddRow(l.Library.Name, l.Library.Version, l.Release.Version)
t2 := table.New()
if len(or.Libraries) > 0 {
t2.SetHeader(tr("Library name"), tr("Installed version"), tr("New version"))
for _, l := range or.Libraries {
t2.AddRow(l.Library.Name, l.Library.Version, l.Release.Version)
}
feedback.Print(tab.Render())
}
logrus.Info("Done")
if len(or.Libraries) > 0 && len(or.Platforms) > 0 {
return t1.Render() + "\n" + t2.Render() // handle the new line between tables
}
return t1.Render() + t2.Render()
}
......@@ -42,7 +42,7 @@ def test_upgrade(run_command):
# Verifies cores and libraries have been updated
result = run_command(["outdated"])
assert result.ok
assert result.stdout == ""
assert result.stdout == "\n"
def test_upgrade_using_library_with_invalid_version(run_command, data_dir):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment