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:
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user