Closed
Description
Bug Report
Current behavior
Some output is not printed in the format specified by the user when they use the new jsonmini
or yaml
options (#1586, #1600) with the --format
flag.
This misformatted output breaks machine readability.
For example:
$ arduino-cli version
arduino-cli.exe Version: nightly-20220124 Commit: 530e671 Date: 2022-01-24T01:28:27Z
$ arduino-cli lib search --format jsonmini Arduino_MKRRGB
Updating index: library_index.json.gz downloaded ? 18677.76% 00m02ss
Updating index: library_index.json.sig downloaded
{"libraries":[{"name":"Arduino_MKRRGB","releases":{"1.0.0":{"author":"Arduino","version":"1.0.0","maintainer":"Arduino \[email protected]\u003e","sentence":"Allows you to draw on your MKR RGB shield.","paragraph":"Depends on the ArduinoGraphics library.","website":"http://github.com/arduino-libraries/Arduino_MKRRGB","category":"Display","architectures":["samd"],"types":["Arduino"],"resources":{"url":"https://downloads.arduino.cc/libraries/github.com/arduino-libraries/Arduino_MKRRGB-1.0.0.zip","archive_filename":"Arduino_MKRRGB-1.0.0.zip","checksum":"SHA-256:0c16c5db92467d65123b4fc16e0d3838d38c26da9137f2c50f3aa0cd17115b4d","size":7797,"cache_path":"libraries"},"provides_includes":["Arduino_MKRRGB.h"],"dependencies":[{"name":"ArduinoGraphics"}]}},"latest":{"author":"Arduino","version":"1.0.0","maintainer":"Arduino \[email protected]\u003e","sentence":"Allows you to draw on your MKR RGB shield.","paragraph":"Depends on the ArduinoGraphics library.","website":"http://github.com/arduino-libraries/Arduino_MKRRGB","category":"Display","architectures":["samd"],"types":["Arduino"],"resources":{"url":"https://downloads.arduino.cc/libraries/github.com/arduino-libraries/Arduino_MKRRGB-1.0.0.zip","archive_filename":"Arduino_MKRRGB-1.0.0.zip","checksum":"SHA-256:0c16c5db92467d65123b4fc16e0d3838d38c26da9137f2c50f3aa0cd17115b4d","size":7797,"cache_path":"libraries"},"provides_includes":["Arduino_MKRRGB.h"],"dependencies":[{"name":"ArduinoGraphics"}]}}],"status":1}
$ arduino-cli lib search --format jsonmini Arduino_MKRRGB | jq '.libraries[0].latest.version'
jq: error (at <stdin>:1): Cannot index number with string "libraries"
parse error: Invalid numeric literal at line 1, column 6
$ arduino-cli lib search --format json Arduino_MKRRGB | jq '.libraries[0].latest.version'
"1.0.0"
$ arduino-cli lib search --format yaml Arduino_MKRRGB
Updating index: library_index.json.gz downloaded ? 19660.80% 00m02ss
Updating index: library_index.json.sig downloaded
libraries:
- name: Arduino_MKRRGB
releases:
1.0.0:
author: Arduino
version: 1.0.0
maintainer: Arduino <[email protected]>
sentence: Allows you to draw on your MKR RGB shield.
paragraph: Depends on the ArduinoGraphics library.
website: http://github.com/arduino-libraries/Arduino_MKRRGB
category: Display
architectures:
- samd
types:
- Arduino
resources:
url: https://downloads.arduino.cc/libraries/github.com/arduino-libraries/Arduino_MKRRGB-1.0.0.zip
archivefilename: Arduino_MKRRGB-1.0.0.zip
checksum: SHA-256:0c16c5db92467d65123b4fc16e0d3838d38c26da9137f2c50f3aa0cd17115b4d
size: 7797
cachepath: libraries
license: ""
providesincludes:
- Arduino_MKRRGB.h
dependencies:
- name: ArduinoGraphics
versionconstraint: ""
latest:
author: Arduino
version: 1.0.0
maintainer: Arduino <[email protected]>
sentence: Allows you to draw on your MKR RGB shield.
paragraph: Depends on the ArduinoGraphics library.
website: http://github.com/arduino-libraries/Arduino_MKRRGB
category: Display
architectures:
- samd
types:
- Arduino
resources:
url: https://downloads.arduino.cc/libraries/github.com/arduino-libraries/Arduino_MKRRGB-1.0.0.zip
archivefilename: Arduino_MKRRGB-1.0.0.zip
checksum: SHA-256:0c16c5db92467d65123b4fc16e0d3838d38c26da9137f2c50f3aa0cd17115b4d
size: 7797
cachepath: libraries
license: ""
providesincludes:
- Arduino_MKRRGB.h
dependencies:
- name: ArduinoGraphics
versionconstraint: ""
status: 1
The code here does not handle the new formats:
arduino-cli/cli/output/rpc_progress.go
Line 36 in 530e671
Expected behavior
All output is printed in the specified format.
A single centralized function is used to determine when output is set to a machine readable format instead of the current jumble of "magic strings" scattered throughout the codebase, which handle only "json".
Environment
- CLI version: nightly-20220124 Commit: 530e671 Date: 2022-01-24T01:28:27Z
- OS and platform: Windows 10
Additional context
#1872 is one specific instance of this general bug.
Originally reported (peripherally) at #1624