Skip to content

JSON, TOML output for tables#1759

Merged
mosteo merged 6 commits into
alire-project:masterfrom
mosteo:feat/machine-output
Sep 23, 2024
Merged

JSON, TOML output for tables#1759
mosteo merged 6 commits into
alire-project:masterfrom
mosteo:feat/machine-output

Conversation

@mosteo

@mosteo mosteo commented Sep 14, 2024

Copy link
Copy Markdown
Member

This is the low hanging fruit for structured output. Commands that use tables for reporting now can output the same information in JSON and TOML formats with a new --format[=JSON] global switch:

$ alr --format search --crates hello
[                                               
  {
    "name": "hello",
    "description": "'Hello, world!' demonstration project"
  },
  {
    "name": "libhello",
    "description": "Basic library demonstration project"
  }
]

$ alr --format=TOML search --crates hello
[[data]]                                        
description = "'Hello, world!' demonstration project"
name = "hello"
[[data]]
description = "Basic library demonstration project"
name = "libhello"

Output is always an array of records (one per row), with headers acting as keys. Since TOML can't have an anonymous top-level array, it is nested within a map with a single data array.

Some commands that use custom output remain unaffected (show, with). Commands that do use tables like this are e.g. search, toolchain, pin, index, version.

@mosteo mosteo force-pushed the feat/machine-output branch 2 times, most recently from a269a00 to fea97e1 Compare September 14, 2024 11:13
@mosteo mosteo force-pushed the feat/machine-output branch from fea97e1 to 83415c8 Compare September 20, 2024 14:12
@mosteo mosteo marked this pull request as ready for review September 20, 2024 14:52
@mosteo mosteo merged commit 62b73c9 into alire-project:master Sep 23, 2024
@mosteo mosteo deleted the feat/machine-output branch September 23, 2024 18:12
@mosteo mosteo mentioned this pull request Oct 3, 2024
2 tasks
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.

2 participants