[lxc-devel] [lxd/master] Lxc client bash completion
lnicolas83 on Github
lxc-bot at linuxcontainers.org
Fri Oct 7 12:07:35 UTC 2016
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 467 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20161007/356804c6/attachment.bin>
-------------- next part --------------
From 3732eea1dbb9b94d7df0bd71620bf9d9ef650d3a Mon Sep 17 00:00:00 2001
From: Nicolas Lisoski <nicolas at lnico.net>
Date: Fri, 7 Oct 2016 14:03:37 +0200
Subject: [PATCH 1/3] Added the command network to lxc-client bash-completion
Signed-off-by: Nicolas Lisoski <nicolas at lnico.net>
---
config/bash/lxd-client | 42 ++++++++++++++++++++++++++++++++++++++++--
1 file changed, 40 insertions(+), 2 deletions(-)
diff --git a/config/bash/lxd-client b/config/bash/lxd-client
index c590aaa..f239aa3 100644
--- a/config/bash/lxd-client
+++ b/config/bash/lxd-client
@@ -33,6 +33,13 @@ _have lxc && {
COMPREPLY=( $( compgen -W "$( lxc profile list )" "$cur" ) )
}
+ _lxd_networks()
+ {
+ COMPREPLY=( $( compgen -W \
+ "$( lxc network list | tail -n +4 | awk '{print $2}' | egrep -v '^(\||^$)' )" "$cur" )
+ )
+ }
+
COMPREPLY=()
# ignore special --foo args
if [[ ${COMP_WORDS[COMP_CWORD]} == -* ]]; then
@@ -40,8 +47,8 @@ _have lxc && {
fi
lxc_cmds="config copy delete exec file help image info init launch \
- list move profile publish remote restart restore shell snapshot start stop \
- version"
+ list move network profile publish remote restart restore shell snapshot \
+ start stop version"
global_keys="core.https_address core.https_allowd_origin \
core.https_allowed_methods core.https_allowed_headers \
@@ -65,6 +72,11 @@ _have lxc && {
volatile.last_state.idmap volatile.last_state.power user.network_mode \
user.meta-data user.user-data user.vendor-data"
+ networks_keys="bridge.driver bridge.external_interfaces bridge.mtu bridge.mode \
+ fan.underlay_subnet fan.overlay_subnet fan.type ipv4.address ipv4.nat ipv4.dhcp \
+ ipv4.dhcp.ranges ipv4.routing ipv6.address ipv6.nat ipv6.dhcp ipv6.dhcp.stateful \
+ ipv6.dhcp.ranges ipv6.routing dns.domain dns.mode raw.dnsmasq"
+
if [ $COMP_CWORD -eq 1 ]; then
COMPREPLY=( $(compgen -W "$lxc_cmds" -- ${COMP_WORDS[COMP_CWORD]}) )
return 0
@@ -148,6 +160,32 @@ _have lxc && {
"move")
_lxd_names
;;
+ "network")
+ case $pos in
+ 2)
+ COMPREPLY=( $(compgen -W "list show create get set unset delete edit attach attach-profile detach detach-profile" -- $cur) )
+ ;;
+ 3)
+ case ${no_dashargs[2]} in
+ "show"|"get"|"set"|"unset"|"delete"|"edit"|"attach"|"attach-profile"|"detach"|"detach-profile")
+ _lxd_networks
+ ;;
+ esac
+ ;;
+ 4)
+ case ${no_dashargs[2]} in
+ "get"|"set"|"unset")
+ COMPREPLY=( $(compgen -W "$networks_keys" -- $cur) )
+ ;;
+ "attach"|"detach"|"detach-profile")
+ _lxd_names
+ ;;
+ "attach-profile")
+ _lxd_profiles
+ ;;
+ esac
+ esac
+ ;;
"profile")
case $pos in
2)
From 39e5a554efa3fd2ea23d498f4d66f9ce23e41484 Mon Sep 17 00:00:00 2001
From: Nicolas Lisoski <nicolas at lnico.net>
Date: Fri, 7 Oct 2016 14:04:17 +0200
Subject: [PATCH 2/3] Allow dash in parameters to lxc-client bash-completion
Signed-off-by: Nicolas Lisoski <nicolas at lnico.net>
---
config/bash/lxd-client | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/config/bash/lxd-client b/config/bash/lxd-client
index f239aa3..9ed7446 100644
--- a/config/bash/lxd-client
+++ b/config/bash/lxd-client
@@ -85,7 +85,7 @@ _have lxc && {
local no_dashargs
cur=${COMP_WORDS[COMP_CWORD]}
- no_dashargs=(${COMP_WORDS[@]//-*})
+ no_dashargs=(${COMP_WORDS[@]// -*})
pos=$((COMP_CWORD - (${#COMP_WORDS[@]} - ${#no_dashargs[@]})))
if [ -z "$cur" ]; then
pos=$(($pos + 1))
From a7c618ecb8e0ce85989c98e2d1e2218ce2ee07e8 Mon Sep 17 00:00:00 2001
From: Nicolas Lisoski <nicolas at lnico.net>
Date: Fri, 7 Oct 2016 14:05:08 +0200
Subject: [PATCH 3/3] Fix _lxd_profiles in lxc-client bash-completion
Signed-off-by: Nicolas Lisoski <nicolas at lnico.net>
---
config/bash/lxd-client | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/config/bash/lxd-client b/config/bash/lxd-client
index 9ed7446..1726ce7 100644
--- a/config/bash/lxd-client
+++ b/config/bash/lxd-client
@@ -30,7 +30,7 @@ _have lxc && {
_lxd_profiles()
{
- COMPREPLY=( $( compgen -W "$( lxc profile list )" "$cur" ) )
+ COMPREPLY=( $( compgen -W "$( lxc profile list | tail -n +4 | awk '{print $2}' | egrep -v '^(\||^$)' )" "$cur" ) )
}
_lxd_networks()
More information about the lxc-devel
mailing list