Skip to content

fix arduino-cli outdated --format json output #1746

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 1 commit into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 31 additions & 14 deletions cli/outdated/outdated.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
2 changes: 1 addition & 1 deletion test/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down