Skip to content
Snippets Groups Projects
Commit 500109e7 authored by Simon Ser's avatar Simon Ser
Browse files

Add flag to read JSON from file

A new -i flag is introduced to allow users to pretty-print a JSON
dump. Users can now share JSON dumps, and optionally post-process
them, e.g. this can be used to only print the connectors:

    drm_info -j | jq '. | map_values(. | {driver,device,connectors,encoders:[],crtcs:[],planes:[]})' | drm_info -i
parent efd95067
No related branches found
No related tags found
1 merge request!75Add flag to read JSON from file
Pipeline #1213523 passed
......@@ -11,24 +11,33 @@
int main(int argc, char *argv[])
{
bool json = false;
bool json = false, input = false;
int opt;
while ((opt = getopt(argc, argv, "j")) != -1) {
while ((opt = getopt(argc, argv, "ji")) != -1) {
switch (opt) {
case 'j':
json = true;
break;
case 'i':
input = true;
break;
default:
fprintf(stderr, "usage: drm_info [-j] [--] [path]...\n");
fprintf(stderr, "usage: drm_info [-j] [-i] [--] [path]...\n");
exit(opt == '?' ? EXIT_SUCCESS : EXIT_FAILURE);
}
}
struct json_object *obj = drm_info(&argv[optind]);
struct json_object *obj;
if (input) {
obj = json_object_from_fd(STDIN_FILENO);
} else {
obj = drm_info(&argv[optind]);
}
if (!obj) {
exit(EXIT_FAILURE);
}
if (json) {
json_object_to_fd(STDOUT_FILENO, obj,
JSON_C_TO_STRING_PRETTY | JSON_C_TO_STRING_SPACED);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment