Skip to content

Invalid JSON output for outdated command #2104

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

Closed
3 tasks done
Renaud11232 opened this issue Mar 10, 2023 · 3 comments · Fixed by #2111
Closed
3 tasks done

Invalid JSON output for outdated command #2104

Renaud11232 opened this issue Mar 10, 2023 · 3 comments · Fixed by #2111
Labels
type: imperfection Perceived defect in any part of project

Comments

@Renaud11232
Copy link

Describe the problem

When running the outdated command with --format json, the produced output is not valid JSON. It looks like it contains two arrays.

To reproduce

Install an outdated library ie:

arduino-cli lib install "[email protected]"

Then run :

arduino-cli --format json outdated

Which produces the following output :

[]
[
  {
    "library": {
      "name": "FastLED",
      "author": "Daniel Garcia",
      "maintainer": "Daniel Garcia \u003c[email protected]\u003e",
      "sentence": "Multi-platform library for controlling dozens of different types of LEDs along with optimized math, effect, and noise functions.",
      "paragraph": "Multi-platform library for controlling dozens of different types of LEDs along with optimized math, effect, and noise functions.",
      "website": "https://github.com/FastLED/FastLED",
      "category": "Display",
      "architectures": [
        "*"
      ],
      "install_dir": "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED",
      "source_dir": "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED",
      "version": "3.3.2",
      "license": "Unspecified",
      "location": 1,
      "examples": [
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\AnalogOutput",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Blink",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\ColorPalette",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\ColorTemperature",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Cylon",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\DemoReel100",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Fire2012",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Fire2012WithPalette",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\FirstLight",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Multiple\\ArrayOfLedArrays",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Multiple\\MirroringSample",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Multiple\\MultiArrays",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Multiple\\MultipleStripsInOneArray",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Multiple\\OctoWS2811Demo",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Multiple\\ParallelOutputDemo",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Noise",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\NoisePlayground",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\NoisePlusPalette",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Pintest",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\Ports\\PJRCSpectrumAnalyzer",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\RGBCalibrate",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\RGBSetDemo",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\SmartMatrix",
        "C:\\Users\\gaspa\\Documents\\Arduino\\libraries\\FastLED\\examples\\XYMatrix"
      ],
      "provides_includes": [
        "FastLED.h",
        "bitswap.h",
        "chipsets.h",
        "color.h",
        "colorpalettes.h",
        "colorutils.h",
        "controller.h",
        "cpp_compat.h",
        "dmx.h",
        "fastled_config.h",
        "fastled_delay.h",
        "fastled_progmem.h",
        "fastpin.h",
        "fastspi.h",
        "fastspi_bitbang.h",
        "fastspi_dma.h",
        "fastspi_nop.h",
        "fastspi_ref.h",
        "fastspi_types.h",
        "hsv2rgb.h",
        "led_sysdefs.h",
        "lib8tion.h",
        "noise.h",
        "pixelset.h",
        "pixeltypes.h",
        "platforms.h",
        "power_mgt.h"
      ]
    },
    "release": {
      "author": "Daniel Garcia",
      "version": "3.5.0",
      "maintainer": "Daniel Garcia \u003c[email protected]\u003e",
      "sentence": "Multi-platform library for controlling dozens of different types of LEDs along with optimized math, effect, and noise functions.",
      "paragraph": "Multi-platform library for controlling dozens of different types of LEDs along with optimized math, effect, and noise functions.",
      "website": "https://github.com/FastLED/FastLED",
      "category": "Display",
      "architectures": [
        "*"
      ],
      "types": [
        "Contributed"
      ]
    }
  }
]

Expected behavior

The output should be valid JSON.

Arduino CLI version

arduino-cli.exe Version: nightly-20230310 Commit: fed439a Date: 2023-03-10T01:35:49Z

Operating system

Windows

Operating system version

Windows 11 22H2

Additional context

No response

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the nightly build
  • My report contains all necessary details
@Renaud11232 Renaud11232 added the type: imperfection Perceived defect in any part of project label Mar 10, 2023
@lluiscampos
Copy link
Contributor

I looked into this (I was just curious) and the issue is that since the simplification of outdated command (commit here, by @cmaglie), what the code is doing is first to list the core packages that are upgradable (same as arduino-cli core list --updatable) and then libraries that are upgradable (./arduino-cli lib list --updatable).

And while this works nicely for the text format, it does not produce valid JSON, because it just prints two separate JSON objects (in your example, an empty [] for core packages and then the libraries part).

The fix that I can think of is refactor a bit the code so that internal/cli/outdated can get the slices returned from both internal/cli/core and internal/cli/lib packages, have its own implementation of Result interface and call feedback.PrintResult directly with the appended slices.

@cmaglie, can you please comment on my suggestion? Thanks!

lluiscampos added a commit to lluiscampos/arduino-cli that referenced this issue Mar 15, 2023
Fixes issue arduino#2104

The code for `internal/cli/core` and `internal/cli/lib` has been
refactored so that we can use only the `Get` functions from
`internal/cli/outdated` package and compose there the table and JSON
object.

For regular text output, the new table will have some extra fields that
either for platforms or for libraries will be blank.

For JSON output, the resulting object will be an array of two arrays:
the outdated platforms and the outdated libraries.

Signed-off-by: Lluís Martínez <[email protected]>
lluiscampos added a commit to lluiscampos/arduino-cli that referenced this issue Mar 15, 2023
Fixes issue arduino#2104

The code for `internal/cli/core` and `internal/cli/lib` has been
refactored so that we can use only the `Get` functions from
`internal/cli/outdated` package and compose there the table and JSON
object.

For regular text output, the new table will have some extra fields that
either for platforms or for libraries will be blank.

For JSON output, the resulting object will be an array of two arrays:
the outdated platforms and the outdated libraries.

Signed-off-by: Lluís Martínez <[email protected]>
@cmaglie
Copy link
Member

cmaglie commented Mar 15, 2023

The fix that I can think of is refactor a bit the code so that internal/cli/outdated can get the slices returned from both internal/cli/core and internal/cli/lib packages, have its own implementation of Result interface and call feedback.PrintResult directly with the appended slices.

That's correct, but I don't know how much refactoring is required to do so. I see that you made a PR already, I guess you tried implementing the idea above, I'll take a look at it ASAP.

lluiscampos added a commit to lluiscampos/arduino-cli that referenced this issue Mar 16, 2023
Fixes issue arduino#2104

The code for `internal/cli/core` and `internal/cli/lib` has been
refactored so that we can use only the `Get` functions from
`internal/cli/outdated` package and compose there the table and JSON
object.

For regular text output, the new table will have some extra fields that
either for platforms or for libraries will be blank.

For JSON output, the resulting object will be an array of two arrays:
the outdated platforms and the outdated libraries.

Signed-off-by: Lluís Martínez <[email protected]>
lluiscampos added a commit to lluiscampos/arduino-cli that referenced this issue Mar 16, 2023
Fixes issue arduino#2104

The code for `internal/cli/core` and `internal/cli/lib` has been
refactored so that we can use only the `Get` functions from
`internal/cli/outdated` package and compose there the table and JSON
object.

For regular text output, the new table will have some extra fields that
either for platforms or for libraries will be blank.

For JSON output, the resulting object will be an array of two arrays:
the outdated platforms and the outdated libraries.

Signed-off-by: Lluís Martínez <[email protected]>
@lluiscampos
Copy link
Contributor

@cmaglie Thanks! Yes, I got started before your feedback as it seemed quite right. The PR is ready for review now 🔍

lluiscampos added a commit to lluiscampos/arduino-cli that referenced this issue Mar 17, 2023
Fixes issue arduino#2104

The code for `internal/cli/core` and `internal/cli/lib` has been
refactored so that we can use only the `Get` functions from
`internal/cli/outdated` package and compose there composited object.

For regular text output, the new table will have some extra fields that
either for platforms or for libraries will be blank.

For JSON and YAML output, the resulting object will have the top-level
keys `platforms` and `libraries` which contain, respectively, the array
of outaded platforms and outdated libraries.

Signed-off-by: Lluís Martínez <[email protected]>
lluiscampos added a commit to lluiscampos/arduino-cli that referenced this issue Mar 17, 2023
Fixes issue arduino#2104

The code for `internal/cli/core` and `internal/cli/lib` has been
refactored so that we can use only the `Get` functions from
`internal/cli/outdated` package and compose there composited object.

For regular text output, the new table will have some extra fields that
either for platforms or for libraries will be blank.

For JSON and YAML output, the resulting object will have the top-level
keys `platforms` and `libraries` which contain, respectively, the array
of outaded platforms and outdated libraries.

Signed-off-by: Lluís Martínez <[email protected]>
cmaglie pushed a commit that referenced this issue Mar 17, 2023
Fixes issue #2104

The code for `internal/cli/core` and `internal/cli/lib` has been
refactored so that we can use only the `Get` functions from
`internal/cli/outdated` package and compose there composited object.

For regular text output, the new table will have some extra fields that
either for platforms or for libraries will be blank.

For JSON and YAML output, the resulting object will have the top-level
keys `platforms` and `libraries` which contain, respectively, the array
of outaded platforms and outdated libraries.

Signed-off-by: Lluís Martínez <[email protected]>
kittaakos pushed a commit to kittaakos/arduino-cli that referenced this issue Mar 21, 2023
Fixes issue arduino#2104

The code for `internal/cli/core` and `internal/cli/lib` has been
refactored so that we can use only the `Get` functions from
`internal/cli/outdated` package and compose there composited object.

For regular text output, the new table will have some extra fields that
either for platforms or for libraries will be blank.

For JSON and YAML output, the resulting object will have the top-level
keys `platforms` and `libraries` which contain, respectively, the array
of outaded platforms and outdated libraries.

Signed-off-by: Lluís Martínez <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: imperfection Perceived defect in any part of project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants