summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAn-Cheng Huang <ancheng@vyatta.com>2007-10-24 18:43:13 -0700
committerAn-Cheng Huang <ancheng@vyatta.com>2007-10-24 18:43:13 -0700
commitb7750af0fa67e28cf6eb607408485dbda194837b (patch)
treeda0729ef58b5fa5ed9673b3d9c11a953cddd8fcc
parent5471d0359de347017c618076cf0f17a06f764952 (diff)
downloadvyatta-cfg-b7750af0fa67e28cf6eb607408485dbda194837b.tar.gz
vyatta-cfg-b7750af0fa67e28cf6eb607408485dbda194837b.zip
* add dynamic "allowed" support for config-mode completion.
* add support for completion help text. * add an example for each of the above ("ethernet" and "ethernet/duplex").
-rw-r--r--etc/bash_completion.d/vyatta-cfg39
-rw-r--r--templates/interfaces/ethernet/node.def3
-rw-r--r--templates/interfaces/ethernet/node.tag/duplex/node.def2
3 files changed, 43 insertions, 1 deletions
diff --git a/etc/bash_completion.d/vyatta-cfg b/etc/bash_completion.d/vyatta-cfg
index 7288b4a..47e33fb 100644
--- a/etc/bash_completion.d/vyatta-cfg
+++ b/etc/bash_completion.d/vyatta-cfg
@@ -290,11 +290,31 @@ get_prefix_filtered_list ()
done
}
+vyatta_parse_tmpl_comp_fields ()
+{
+ # $1: tmpl
+ # $2: field name
+ sed -n '
+ /^#'"$2"':/,$ {
+ s/^#'"$2"'://
+ h
+ :b
+ $ { x; p; q }
+ n
+ /^#[a-z]\+:/ { x; p; q }
+ s/^#//
+ H
+ bb
+ }
+ ' $1
+}
+
declare vyatta_cfg_help=""
declare vyatta_cfg_type=""
declare vyatta_cfg_tag=0
declare vyatta_cfg_multi=0
declare -a vyatta_cfg_allowed=()
+declare vyatta_cfg_comp_help=""
vyatta_parse_tmpl ()
{
# $1: tmpl
@@ -303,6 +323,7 @@ vyatta_parse_tmpl ()
vyatta_cfg_tag=0
vyatta_cfg_multi=0
vyatta_cfg_allowed=()
+ vyatta_cfg_comp_help=''
if [ ! -r $1 ]; then
return
fi
@@ -320,6 +341,13 @@ vyatta_parse_tmpl ()
s/^multi:/vyatta_cfg_multi=1/p
s/^type:[ ]\+\([^ ]\+\)$/vyatta_cfg_type=\1/p
' $1`
+
+ local acmd=$(vyatta_parse_tmpl_comp_fields $1 "allowed")
+ vyatta_cfg_comp_help=$(vyatta_parse_tmpl_comp_fields $1 "comp_help")
+
+ if (( ${#vyatta_cfg_allowed[@]} == 0 )); then
+ vyatta_cfg_allowed=($(eval "$acmd"))
+ fi
if [ -z "$vyatta_cfg_help" ]; then
vyatta_cfg_help='<No help text available>'
fi
@@ -335,6 +363,10 @@ generate_help_text ()
eval "items=( \"\${$1[@]}\" )"
eval "helps=( \"\${$2[@]}\" )"
vyatta_help_text="\\nPossible completions:"
+ if [ -n "$vyatta_cfg_comp_help" ]; then
+ vyatta_help_text="${vyatta_help_text}\\n${vyatta_cfg_comp_help}"
+ return 0
+ fi
for (( idx = 0; idx < ${#items[@]}; idx++ )); do
vyatta_help_text="${vyatta_help_text}\\n\\x20\\x20"
if [ ${#items[$idx]} -lt 6 ]; then
@@ -532,7 +564,7 @@ vyatta_do_complete ()
ENDCOMMENT
if (( do_help )); then
- echo -en $vyatta_help_text
+ printf "$vyatta_help_text"
COMPREPLY=( "" " " )
else
COMPREPLY=( $(compgen -W "${vyatta_completions[*]}" \
@@ -543,6 +575,9 @@ ENDCOMMENT
vyatta_config_complete ()
{
+ local restore_shopts=$( shopt -p extglob nullglob | tr \\n \; )
+ shopt -s extglob nullglob
+
if [ "$COMP_LINE" == "$VYATTA_COMP_LINE" ]; then
VYATTA_COMP_LINE=''
vyatta_do_help=1
@@ -767,6 +802,8 @@ vyatta_config_complete ()
vyatta_do_complete
return
fi
+
+ eval $restore_shopts
}
DEF_GROUP=quaggavty
diff --git a/templates/interfaces/ethernet/node.def b/templates/interfaces/ethernet/node.def
index b5a320e..8806643 100644
--- a/templates/interfaces/ethernet/node.def
+++ b/templates/interfaces/ethernet/node.def
@@ -6,3 +6,6 @@ syntax: exec " \
echo ethernet interface $(@) doesn\\'t exist on this system ; \
exit 1 ; \
fi ; "
+#allowed: local -a array ;
+# array=( /sys/class/net/{eth,vmnet}* ) ;
+# echo -n ${array[@]##*/}
diff --git a/templates/interfaces/ethernet/node.tag/duplex/node.def b/templates/interfaces/ethernet/node.tag/duplex/node.def
index 70df798..684d4ec 100644
--- a/templates/interfaces/ethernet/node.tag/duplex/node.def
+++ b/templates/interfaces/ethernet/node.tag/duplex/node.def
@@ -4,3 +4,5 @@ syntax: $(@) in "half", "full"; "duplex must be half or full"
commit: $(../speed) != ""; "if duplex is hardcoded, speed must also be hardcoded"
update: "sudo ethtool -s $(../@) speed $(../speed/@) duplex $(@) autoneg off"
delete: "sudo ethtool -s $(../@) autoneg on"
+#comp_help: half\t\tHalf duplex
+# full\t\tFull duplex