mirror of
https://github.com/systemd/systemd.git
synced 2025-03-11 20:58:27 +03:00
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:
parent
db21c2ec70
commit
2bf618331d
@ -201,6 +201,7 @@
|
||||
<xi:include href="standard-options.xml" xpointer="help" />
|
||||
<xi:include href="standard-options.xml" xpointer="version" />
|
||||
<xi:include href="standard-options.xml" xpointer="json" />
|
||||
<xi:include href="standard-options.xml" xpointer="j" />
|
||||
</variablelist>
|
||||
</refsect1>
|
||||
|
||||
|
@ -35,7 +35,7 @@ _hostnamectl() {
|
||||
local i verb comps
|
||||
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
|
||||
local -A OPTS=(
|
||||
[STANDALONE]='-h --help --version --transient --static --pretty --no-ask-password'
|
||||
[STANDALONE]='-h --help --version --transient --static --pretty --no-ask-password -j'
|
||||
[ARG]='-H --host -M --machine --json'
|
||||
)
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user