Skip to content

Add format flag#26

Open
mrmara wants to merge 4 commits into
mainfrom
IENG-2485-format-flag-lscompute
Open

Add format flag#26
mrmara wants to merge 4 commits into
mainfrom
IENG-2485-format-flag-lscompute

Conversation

@mrmara

@mrmara mrmara commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Usage:

lscompute --format plain|json

plain format is default

Exaple Output:

$ lscompute
cpus:
  - architecture: amd64
    manufacturer-id: AuthenticAMD
    flags: [fpu, vme, de, pse, tsc, msr, pae, mce, cx8,...]
memory:
  total-ram: 87.7G
  total-swap: 8.0G
disk:
  /var/lib/snapd/snaps:
    total: 1.8T
    avail: 41.1G
devices:
  - bus: pci
    slot: '0000:00:00.0'
    bus-number: "0x0"
    device-class: "0x600"
    vendor-id: "0x1022"
    device-id: "0x1122"
    subvendor-id: "0x17AA"
    subdevice-id: "0x512E"
    vendor-name: Advanced Micro Devices, Inc. [AMD]
    device-name: Krackan Root Complex
    subvendor-name: Lenovo
  - bus: pci
    slot: '0000:00:00.2'
    bus-number: "0x0"
    device-class: "0x806"
    vendor-id: "0x1022"
    device-id: "0x1123"
    subvendor-id: "0x17AA"
    subdevice-id: "0x512E"
    vendor-name: Advanced Micro Devices, Inc. [AMD]
    device-name: Krackan IOMMU
    subvendor-name: Lenovo
  - ...
{
  "cpus": [
    {
      "architecture": "amd64",
      "manufacturer-id": "AuthenticAMD",
      "flags": [
        "fpu",
        "vme",
        "de",
        "pse",
        "tsc",
        "msr",
        "pae",
        "mce",
        "cx8",
        ...
      ]
    }
  ],
  "memory": {
    "total-ram": 94220341248,
    "total-swap": 8589930496
  },
  "disk": {
    "/var/lib/snapd/snaps": {
      "total": 2011859927040,
      "avail": 44169400320
    }
  },
  "devices": [
    {
      "bus": "pci",
      "slot": "0000:00:00.0",
      "bus-number": "0x0",
      "device-class": "0x600",
      "vendor-id": "0x1022",
      "device-id": "0x1122",
      "subvendor-id": "0x17AA",
      "subdevice-id": "0x512E",
      "vendor-name": "Advanced Micro Devices, Inc. [AMD]",
      "device-name": "Krackan Root Complex",
      "subvendor-name": "Lenovo"
    },
    {
      "bus": "pci",
      "slot": "0000:00:00.2",
      "bus-number": "0x0",
      "device-class": "0x806",
      "vendor-id": "0x1022",
      "device-id": "0x1123",
      "subvendor-id": "0x17AA",
      "subdevice-id": "0x512E",
      "vendor-name": "Advanced Micro Devices, Inc. [AMD]",
      "device-name": "Krackan IOMMU",
      "subvendor-name": "Lenovo"
    },
    {
      ...
    }
  ]
}

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a --format CLI flag to lscompute to support multiple output serializations, making the default output a human-readable “plain” summary while preserving JSON output for machine consumption.

Changes:

  • Add --format flag to select plain (default) or json output.
  • Introduce pkg/machine formatting layer (Marshal) with a plain-text renderer.
  • Update usage documentation and add example-based tests for both formats.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
README.md Updates usage docs to describe default plain output and --format flag.
cmd/lscompute/main.go Adds flag parsing and routes output through machine.Marshal.
pkg/machine/format.go Implements format selection + plain-text rendering and byte formatting helpers.
pkg/machine/format_test.go Adds Go examples for JSON and plain output rendering using test data.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cmd/lscompute/main.go Outdated
Comment thread pkg/machine/format.go
Comment thread pkg/machine/format.go Outdated
Comment thread pkg/machine/format.go Outdated
Comment thread pkg/machine/format.go Outdated
Comment thread pkg/machine/format_test.go Outdated
Comment thread pkg/machine/format.go Outdated
Comment thread pkg/machine/format_test.go Outdated
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.

3 participants