mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-04-29 01:23:41 +00:00
Refactor __lxc_groups()
to __lxc_get_groups()
.
Make code logic be more clear to what it is being done. Signed-off-by: Edênis Freindorfer Azevedo <edenisfa@gmail.com>
This commit is contained in:
parent
f73bcca529
commit
4cd0915e76
@ -88,7 +88,7 @@ __lxc_get_snapshots() {
|
|||||||
if [[ ! "${snaps[*]}" =~ ${nosnapxp} ]]; then
|
if [[ ! "${snaps[*]}" =~ ${nosnapxp} ]]; then
|
||||||
for i in "${!snaps[@]}"; do
|
for i in "${!snaps[@]}"; do
|
||||||
read -r -e -a line <<< "${snaps[${i}]}"
|
read -r -e -a line <<< "${snaps[${i}]}"
|
||||||
printf "%s " "${line[0]}"
|
command printf "%s " "${line[0]}"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -132,7 +132,7 @@ __lxc_concat_array_sep() {
|
|||||||
concat+="${word}${sep}"
|
concat+="${word}${sep}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
printf "%s" "${concat}"
|
command printf "%s" "${concat}"
|
||||||
}
|
}
|
||||||
|
|
||||||
__lxc_check_completion_avail() {
|
__lxc_check_completion_avail() {
|
||||||
@ -308,14 +308,22 @@ _lxc_attach() {
|
|||||||
} &&
|
} &&
|
||||||
complete -F _lxc_attach lxc-attach
|
complete -F _lxc_attach lxc-attach
|
||||||
|
|
||||||
__lxc_groups() {
|
__lxc_get_groups() {
|
||||||
declare -A groups
|
declare -A groups
|
||||||
for line in "$(command lxc-ls -f --fancy-format GROUPS | command sed -e '/^-/d' -e '1d' -e 's/,/ /g')"; do
|
local key
|
||||||
for grp in $line; do
|
declare -a linegroups
|
||||||
groups+=([${grp}]=1)
|
# Discard "GROUPS" header and lines without any groups (with only '-').
|
||||||
|
mapfile -s 1 -t lines < <(command lxc-ls -f --fancy-format GROUPS | command sed -e '/^-/d')
|
||||||
|
for line in "${lines[@]}"; do
|
||||||
|
line=$(command echo -e "${line}" | command sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
|
||||||
|
IFS=$',' read -r -e -a linegroups <<< "${line}"
|
||||||
|
for entry in "${linegroups[@]}"; do
|
||||||
|
key=$(printf "%q" "${entry}")
|
||||||
|
groups+=(["${key}"]=1)
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
printf "%s " "${!groups[@]}"
|
declare -a output=("${!groups[@]}")
|
||||||
|
command printf "%s" "${output[*]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
_lxc_autostart() {
|
_lxc_autostart() {
|
||||||
@ -335,7 +343,7 @@ _lxc_autostart() {
|
|||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
--groups | -g )
|
--groups | -g )
|
||||||
__lxc_piped_args "${cur}" ',' $( __lxc_groups ) ','
|
__lxc_piped_args "${cur}" ',' $( __lxc_get_groups ) ','
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -758,7 +766,7 @@ _lxc_ls() {
|
|||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
--groups | -g )
|
--groups | -g )
|
||||||
__lxc_piped_args "${cur}" ',' $( __lxc_groups ) ','
|
__lxc_piped_args "${cur}" ',' $( __lxc_get_groups ) ','
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
--nesting )
|
--nesting )
|
||||||
|
Loading…
Reference in New Issue
Block a user