Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON, TOML output for tables #1759

Merged
merged 6 commits into from
Sep 23, 2024
Merged

Conversation

mosteo
Copy link
Member

@mosteo mosteo commented Sep 14, 2024

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
26 checks passed
@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