networkctl: introduce --json option for "status" and "list" commands

When `--json` option is specified, "status" and "list" commands gives
the same information, as originally "list" just gives partial
information of "status" in different format.
This commit is contained in:
Yu Watanabe
2021-05-14 09:18:29 +09:00
parent fec7a9e0ac
commit bfc2b05e59
4 changed files with 153 additions and 2 deletions
+14 -1
View File
@@ -33,7 +33,7 @@ _networkctl() {
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} words cword
local -A OPTS=(
[STANDALONE]='-a --all -h --help --version --no-pager --no-legend -s --stats -l --full'
[ARG]='-n --lines'
[ARG]='-n --lines --json'
)
local -A VERBS=(
@@ -51,6 +51,19 @@ _networkctl() {
fi
done
if __contains_word "$prev" ${OPTS[ARG]}; then
case $prev in
--json)
comps=$(networkctl --json=help | sort 2>/dev/null)
;;
*)
return 0
;;
esac
COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
return 0
fi
if [[ "$cur" = -* ]]; then
COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
return 0
+8
View File
@@ -39,10 +39,18 @@
fi
}
(( $+functions[_networkctl_get_json] )) || _networkctl_get_json()
{
local -a _json_forms
_json_forms=( $(networkctl --json=help 2>/dev/null) )
_values 'format' $_json_forms
}
_arguments \
{-a,--all}'[Show all links with status]' \
'--no-pager[Do not pipe output into a pager]' \
'--no-legend[Do not print the column headers]' \
{-h,--help}'[Show this help]' \
'--version[Show package version]' \
'--json[Shows output formatted as JSON]:format:_networkctl_get_json' \
'*::networkctl commands:_networkctl_commands'