Skip to content

Add --output=json to ls subcommands#342

Open
miekg wants to merge 3 commits into
psviderski:mainfrom
miekg:miek/26/apr29wo/jsonflag
Open

Add --output=json to ls subcommands#342
miekg wants to merge 3 commits into
psviderski:mainfrom
miekg:miek/26/apr29wo/jsonflag

Conversation

@miekg
Copy link
Copy Markdown
Contributor

@miekg miekg commented Apr 29, 2026

This PR add --output=json to only the command that have an ls.go. The json keys are copied from docker and are camelCase, json struct tags are added where needed.

It does not change any of the inspect commands, that should be another issue. It also doesn't do any prework for future output formats, it only handles json.

Fixes: #338 #337

This PR add --output=json to _only_ the command that have an ls.go.
The json keys are copied from docker and are camelCase, json struct tags
are added where needed.

It does _not_ change any of the inspect commands, that should be another
issue. It also doesn't do any prework for future output formats, it only
handles json.

Fixes: psviderski#338 psviderski#337

Signed-off-by: Miek Gieben <miek@miek.nl>
@miekg
Copy link
Copy Markdown
Contributor Author

miekg commented Apr 29, 2026

you can't (easily) change the struct tags of generated protobufs ... these are now all in snake case.
See golang/protobuf#52

Signed-off-by: Miek Gieben <miek@miek.nl>
@miekg
Copy link
Copy Markdown
Contributor Author

miekg commented Apr 29, 2026

example for machine:

% uc machine ls
NAME           STATE   ADDRESS         PUBLIC IP       WIREGUARD ENDPOINTS   MACHINE ID
machine-781l   Up      10.210.0.1/24   131.174.88.77   131.174.88.77:51820   c22073beee04bf9b1861e53c21023d2d
machine-9q7y   Up      10.210.1.1/24   131.174.88.78   131.174.88.78:51820   212fd73438b53ebfb7dd531da4c6ed41

and % uc machine ls --output=json

{
  "Machines": [
    {
      "machine": {
        "id": "c22073beee04bf9b1861e53c21023d2d",
        "name": "machine-781l",
        "network": {
          "subnet": {
            "ip": "10.210.0.0",
            "bits": 24
          },
          "management_ip": "fdcc:fb07:d7f4:2509:ae43:19af:90b:1147",
          "endpoints": [
            "131.174.88.77:51820"
          ],
          "public_key": "+wfX9CUJrkMZrwkLEUcyitNurEAcuki3VqTyidcsVGw="
        },
        "public_ip": "131.174.88.77"
      },
      "state": 1
    },
    {
      "machine": {
        "id": "212fd73438b53ebfb7dd531da4c6ed41",
        "name": "machine-9q7y",
        "network": {
          "subnet": {
            "ip": "10.210.1.0",
            "bits": 24
          },
          "management_ip": "fdcc:7911:76ad:b00c:9f0e:5ed4:9b81:ee70",
          "endpoints": [
            "131.174.88.78:51820"
          ],
          "public_key": "eRF2rbAMnw5e1JuB7nCwxYMaH1lsoMMwuS63c+Dm9lI="
        },
        "public_ip": "131.174.88.78"
      },
      "state": 1
    }
  ]
}

@miekg
Copy link
Copy Markdown
Contributor Author

miekg commented Apr 29, 2026

as wg only has show command that one didn't get a --output=json

@miekg
Copy link
Copy Markdown
Contributor Author

miekg commented Apr 29, 2026

and volume for instance - different keys:

% uc volume ls --output=json                                                                                                   ~miekg/uncloud/cmd/uncloud miek/26/apr29wo/jsonflag
{
  "Volumes": [
    {
      "MachineID": "212fd73438b53ebfb7dd531da4c6ed41",
      "MachineName": "machine-9q7y",
      "Volume": {
        "CreatedAt": "2026-04-24T11:23:14Z",
        "Driver": "local",
        "Labels": {
          "nl.ru.science.backup": "kopia",
          "uncloud.managed": ""
        },
        "Mountpoint": "/var/lib/docker/volumes/atomdns_data/_data",
        "Name": "atomdns_data",
        "Options": null,
        "Scope": "local"
      }
    },
    {
      "MachineID": "212fd73438b53ebfb7dd531da4c6ed41",
      "MachineName": "machine-9q7y",
      "Volume": {
        "CreatedAt": "2026-04-24T11:10:25Z",
        "Driver": "local",
        "Labels": {
          "uncloud.managed": ""
        },
        "Mountpoint": "/var/lib/docker/volumes/db_data/_data",
        "Name": "db_data",
        "Options": null,
        "Scope": "local"
      }
    }
  ]
}

dont know how much this actually matter in json actualy...

Well is does matter. Adding a post-process json function is very easy, so we could rewrite all the keys into a way to makes it all more consistent

Signed-off-by: Miek Gieben <miek@miek.nl>
This was referenced Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add more inspect subcommands

1 participant