report: add -j shortcut

json output is going to be used very frequently, hence provide a
shortcut for it, like many our tools do it.
This commit is contained in:
Lennart Poettering
2026-02-20 08:25:12 +01:00
parent 39225c9904
commit 442040e716
2 changed files with 8 additions and 1 deletions
+1
View File
@@ -90,6 +90,7 @@
<xi:include href="standard-options.xml" xpointer="no-pager" />
<xi:include href="standard-options.xml" xpointer="json" />
<xi:include href="standard-options.xml" xpointer="j" />
<xi:include href="standard-options.xml" xpointer="help" />
<xi:include href="standard-options.xml" xpointer="version" />
</variablelist>
+7 -1
View File
@@ -607,6 +607,8 @@ static int verb_help(int argc, char *argv[], void *userdata) {
" --system Connect to system service manager (default)\n"
" --json=pretty|short\n"
" Configure JSON output\n"
" -j Equivalent to --json=pretty (on TTY) or --json=short\n"
" (otherwise)\n"
"\nSee the %2$s for details.\n",
program_invocation_short_name,
link,
@@ -642,7 +644,7 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0)
while ((c = getopt_long(argc, argv, "hj", options, NULL)) >= 0)
switch (c) {
case 'h':
return verb_help(/* argc= */ 0, /* argv= */ NULL, /* userdata= */ NULL);
@@ -669,6 +671,10 @@ static int parse_argv(int argc, char *argv[]) {
break;
case 'j':
arg_json_format_flags = SD_JSON_FORMAT_PRETTY_AUTO|SD_JSON_FORMAT_COLOR_AUTO;
break;
case '?':
return -EINVAL;