]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
loginctl: optionally output table in json
authorLennart Poettering <lennart@poettering.net>
Mon, 3 Dec 2018 19:46:33 +0000 (20:46 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 3 Dec 2018 21:42:38 +0000 (22:42 +0100)
This works now:

  $ loginctl list-session --output=json-pretty

src/login/loginctl.c

index fb5240d7d368c2c95e0bd32974ef6b572f36ace2..d0987fcd1a5cd8ac9c8145113dacdad99493ebd5 100644 (file)
@@ -101,7 +101,10 @@ static int show_table(Table *table, const char *word) {
 
                 table_set_header(table, arg_legend);
 
-                r = table_print(table, NULL);
+                if (OUTPUT_MODE_IS_JSON(arg_output))
+                        r = table_print_json(table, NULL, output_mode_to_json_format_flags(arg_output) | JSON_FORMAT_COLOR_AUTO);
+                else
+                        r = table_print(table, NULL);
                 if (r < 0)
                         return log_error_errno(r, "Failed to show table: %m");
         }
@@ -1434,6 +1437,10 @@ static int parse_argv(int argc, char *argv[]) {
                         if (arg_output < 0)
                                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
                                                        "Unknown output '%s'.", optarg);
+
+                        if (OUTPUT_MODE_IS_JSON(arg_output))
+                                arg_legend = false;
+
                         break;
 
                 case ARG_NO_PAGER: