hostnamectl: add -j switch for quick json output

We already support -j as shortcut for JSON mode in various tools. Let's
add one more. We probably should add this systematically (at least where
it doesn't conflict with an existing -j switch with other purpose). But
I am too lazy to add that now.
This commit is contained in:
Lennart Poettering
2024-01-22 14:39:22 +01:00
parent db21c2ec70
commit 2bf618331d
3 changed files with 8 additions and 2 deletions
+6 -1
View File
@@ -616,6 +616,7 @@ static int help(void) {
" --pretty Only set pretty hostname\n"
" --json=pretty|short|off\n"
" Generate JSON output\n"
" -j Same as --json=pretty on tty, --json=short otherwise\n"
"\nSee the %s for details.\n",
program_invocation_short_name,
ansi_highlight(),
@@ -658,7 +659,7 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);
while ((c = getopt_long(argc, argv, "hH:M:", options, NULL)) >= 0)
while ((c = getopt_long(argc, argv, "hH:M:j", options, NULL)) >= 0)
switch (c) {
@@ -701,6 +702,10 @@ static int parse_argv(int argc, char *argv[]) {
break;
case 'j':
arg_json_format_flags = JSON_FORMAT_PRETTY_AUTO|JSON_FORMAT_COLOR_AUTO;
break;
case '?':
return -EINVAL;