ionos-cloud / ionosctl

The IONOS Cloud CLI (ionosctl) gives the ability to manage IONOS Cloud infrastructure directly from Command Line.
Apache License 2.0
30 stars 6 forks source link

-o json Output is different from API #249

Closed maboehm closed 1 year ago

maboehm commented 1 year ago

Description

The JSON output generated by addding the flag -o json to any command is different from the output produced when calling an endpoint directly. E.g.

$ ionosctl datacenter list -o json | jq 'keys'
[
  "Resources"
]
$ curl -s https://api.ionos.com/cloudapi/v6/datacenters --user "$IONOS_USERNAME:$IONOS_PASSWORD" | jq keys
[
  "_links",
  "href",
  "id",
  "items",
  "limit",
  "offset",
  "type"
]

I don't necessarily mind that the metadata is lost, but the fact that the top level key items gets renamed to Resources is very inconvenient - e.g. I would have expected that a jq query works the same whether I use the API directly or ionosctl -o json

Expected behavior

JSON fields in the API Response are not renamed

Environment

Ionosctl version:

v6.5.1

References

This is caused by the way resulting lists are passed to the Printer, which specifies the JSON representation to be Resources https://github.com/ionos-cloud/ionosctl/blob/master/pkg/printer/result.go#L132

avirtopeanu-ionos commented 1 year ago

Hi, -o json is now outputting items since v6.6.1. the rest of the keys being lost is a bit more work. it's due to the duplicated print funcs which would take a bit more work to fix. i'd rather not close the issue yet until these are fixed

avirtopeanu-ionos commented 1 year ago

Will be fixed by #348

avirtopeanu-ionos commented 1 year ago

348 has been merged into master, now all API fields will be correctly shown in -o json

 % i dc ls -o json | jq keys
[
  "_links",
  "href",
  "id",
  "items",
  "limit",
  "offset",
  "type"
]

You can expect this to be included in the next release!