Commit 23d088e
committed
Add tabular output with --format flag
Tabular output is much easier to quickly scan for value, as well as
being more amenable to traditional UNIX scripting. For example,
compare finding the block_size for an image in the following output:
$ oxide image list --format=json
[
{
"block_size": 512,
"description": "Debian 13 generic cloud image",
"id": "3672f476-51ff-49ab-bd2c-723151a921c6",
"name": "debian-13",
"os": "Debian",
"size": 3221225472,
"time_created": "2025-08-11T16:48:17.827861Z",
"time_modified": "2025-08-11T16:52:23.411189Z",
"version": "13"
}, {
"block_size": 4096,
"description": "Silo image for Packer acceptance testing.",
"id": "f13b140e-4d34-4060-b898-6316cdcc2f1e",
"name": "packer-acc-test-silo-image",
"os": "",
"size": 1073741824,
"time_created": "2025-05-15T23:11:14.015948Z",
"time_modified": "2025-05-15T23:12:02.098119Z",
"version": ""
}
]
Versus:
$ oxide image list --format=table:name,block_size
NAME BLOCK_SIZE
debian-13 512
packer-acc-test-silo-image 4096
For query operations with a response type that is amenable to tabular
formatting, we add a `--format` flag to the subcommand. This takes an
optional comma-separated list of field names to print, as larger
response items can easily overflow typical terminal widths. The
available field names are listed in the `--help` output for the
subcommand.
The existing JSON format remains the default. Future changes may add the
ability to set a default format on a per-command basis.
Not all API return values can be reasonably formatted as a table.
Endpoints returning `()`, byte streams, and unstructured
`serde_json::Value` objects are deliberately excluded.
Internally, this is implemented using the newly added `ResponseFields`
trait, which xtask creates as part of the generated CLI. This enables
getting the field names of a type and accessing them as a
`serde_json::Value` via their name.1 parent 16e10e5 commit 23d088e
File tree
19 files changed
+5525
-61
lines changed- cli
- docs
- src
- tests
- data
- xtask
- src
19 files changed
+5525
-61
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| 36 | + | |
35 | 37 | | |
36 | 38 | | |
37 | 39 | | |
| |||
44 | 46 | | |
45 | 47 | | |
46 | 48 | | |
| 49 | + | |
47 | 50 | | |
48 | 51 | | |
49 | 52 | | |
| 53 | + | |
50 | 54 | | |
51 | 55 | | |
52 | 56 | | |
| |||
59 | 63 | | |
60 | 64 | | |
61 | 65 | | |
| 66 | + | |
62 | 67 | | |
63 | 68 | | |
64 | 69 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
0 commit comments