summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README17
-rw-r--r--etc/bash_completion.d/vyatta-op59
-rw-r--r--templates/set/date/node.tag/node.def2
-rw-r--r--templates/set/date/ntp/node.tag/node.def3
-rw-r--r--templates/set/node.tag/node.def2
-rw-r--r--templates/show/ntp/node.tag/node.def3
6 files changed, 39 insertions, 47 deletions
diff --git a/README b/README
index 44cf084..7d69913 100644
--- a/README
+++ b/README
@@ -31,17 +31,18 @@ function, $1 is the command name rather than the usual $0. So, the
command "show interfaces ethernet eth0" would evaluate the respective
run command with $4 == eth0.
-The variable argument .../node.tag/node.def files must also define an
-"allowed" value field that is a shell expression that outputs (stdout)
-the list of values;
-like .../templates/show/interfaces/ethernet/node.tag/node.def:
+The variable argument .../node.tag/node.def files may also define an
+"allowed" field. This is a misnomer since it's really used to produce
+a list of possible completions rather than what is allowed during
+execution. The fields contents are evaluated shell expression that
+outputs (stdout) the list of possible completion values; like
+.../templates/show/interfaces/ethernet/node.tag/node.def:
help: "Show given ethernet interface information"
allowed: local -a array=( /sys/class/net/{eth,vmnet}* ) ;
echo -n ${array[@]##*/}
run: ${vyatta_bindir}/vyatta-show-interfaces ethernet $4
-You may use the "--" wild card, for variable arguments with no
-possible completion:
-
-allowed: echo -n --
+A blank or missing "allowed" field means that there is no completion
+for the respective node; for such nodes a '*' placeholder tag is
+displayed with the help text.
diff --git a/etc/bash_completion.d/vyatta-op b/etc/bash_completion.d/vyatta-op
index 10d65e4..4b6bdfc 100644
--- a/etc/bash_completion.d/vyatta-op
+++ b/etc/bash_completion.d/vyatta-op
@@ -83,29 +83,24 @@ _vyatta_op_set_allowed_subdirs ()
tag_ndef=${vyatta_op_templates}/${dir}/node.tag/node.def
if [ -f $tag_ndef ] ; then
local acmd=$( _vyatta_op_get_node_def_field $tag_ndef allowed )
- _vyatta_op_allowed+=($( eval "$acmd" ))
+ local -a a=($( eval "$acmd" ))
+ if [ ${#a[@]} -ne 0 ] ; then
+ _vyatta_op_allowed+=( "${a[@]}" )
+ else
+ _vyatta_op_allowed+=( "" )
+ fi
fi
-
eval $restore_shopts
}
-_vyatta_op_set_allowed ()
-{
- local nullglob=$( shopt -p nullglob )
- shopt -s nullglob
- _vyatta_op_allowed=($( eval "$( _vyatta_op_get_node_def_field $_vyatta_op_node_def allowed )" ))
- eval $nullglob
-}
-
_vyatta_op_is_allowed ()
{
- local arg=$1 allowed
+ local arg=$1
# return immediately if nothing allowed
[ ${#_vyatta_op_allowed[@]} -ne 0 ] || return
- for allowed in ${_vyatta_op_allowed[@]} ; do
- # -- is wildcard that allows anything
- [ $allowed == -- ] && return
+ for allowed in "${_vyatta_op_allowed[@]}" ; do
+ [ -z "$allowed" ] && return
[ "$arg" == $allowed ] && return
done
false
@@ -148,14 +143,6 @@ _vyatta_op_scan ()
# no template
break
fi
- _vyatta_op_node_def=$ndef
- _vyatta_op_set_allowed
- if ! _vyatta_op_is_allowed $arg ; then
- # invalid tag value.
- # XXX probably display "allowed:"-specific help string when
- # that is supported?
- break
- fi
fi
last_tag=1
tpath=$_tpath
@@ -249,13 +236,17 @@ _vyatta_op_help ()
subtag=$_vyatta_op_node_path/node.tag/node.def
eval $restore_shopts
if [ -f $subtag ]; then
- allowed=($( eval "$( _vyatta_op_get_node_def_field $subtag allowed )" ))
+ local acmd=$( _vyatta_op_get_node_def_field $subtag allowed )
+ allowed=($( eval "$acmd" ))
help=$( _vyatta_op_get_node_def_field $subtag help )
if [ ${#allowed[@]} -ne 0 ] ; then
for a in "${allowed[@]}"; do
- hcomps+=( "$a" )
+ hcomps+=( "${a:-*}" )
hstrs+=( "$help" )
done
+ else
+ hcomps=( '*' )
+ hstrs=( "$help" )
fi
fi
@@ -282,21 +273,23 @@ _vyatta_op_help ()
_vyatta_op_expand ()
{
local cur=${COMP_WORDS[COMP_CWORD]}
- local a w
if _vyatta_op_scan 0 "${COMP_WORDS[@]}" ; then
- a="${_vyatta_op_allowed[*]}"
- if [ "$a" != '--' ] ; then
- w=$a
- else
- w="" # donot expand wildcard
+ COMPREPLY=( )
+ if [ -n "${_vyatta_op_allowed[*]}" ] ; then
+ for a in "${_vyatta_op_allowed[@]}" ; do
+ if [ -n "$a" ] ; then
+ COMPREPLY+=($( compgen -W "$a" -- $cur ))
+ else
+ COMPREPLY+=( "" )
+ fi
+ done
fi
- COMPREPLY=($( compgen -W "$w" -- $cur ))
- if [[ ${#COMPREPLY[@]} -ne 0 || "$a" == '--' ]] &&
+ if [[ ${#COMPREPLY[@]} -ne 0 || -z "${_vyatta_op_allowed[*]}" ]] &&
[[ "${COMP_WORDS[*]}" == "${_vyatta_op_comp_words[*]}" ]]
then
_vyatta_op_help
- COMPREPLY=($( compgen -o nospace -W "______________ ..." ))
+ COMPREPLY=( "" " " )
_vyatta_op_comp_words=( )
else
_vyatta_op_comp_words=( "${COMP_WORDS[@]}" )
diff --git a/templates/set/date/node.tag/node.def b/templates/set/date/node.tag/node.def
index f508bf3..778a408 100644
--- a/templates/set/date/node.tag/node.def
+++ b/templates/set/date/node.tag/node.def
@@ -1,3 +1,3 @@
help: Set date and time: MMDDhhmm[.ss]YYYY
-allowed: echo -n --
+allowed:
run: sudo /bin/date $3
diff --git a/templates/set/date/ntp/node.tag/node.def b/templates/set/date/ntp/node.tag/node.def
index f8be449..be4de16 100644
--- a/templates/set/date/ntp/node.tag/node.def
+++ b/templates/set/date/ntp/node.tag/node.def
@@ -1,4 +1,3 @@
help: Set system date and time with given NTP server
-allowed: sed 's/#.*//; s/^[^ \t]*[ \t]//; /^$/d' ${HOSTFILE:-/dev/null} ;
- echo --
+allowed: sed 's/#.*//; s/^[^ \t]*[ \t]//; /^$/d' ${HOSTFILE:-/dev/null}
run: sudo ntpdate ${4:-ntp.vyatta.com}
diff --git a/templates/set/node.tag/node.def b/templates/set/node.tag/node.def
index dd11fb5..be8e567 100644
--- a/templates/set/node.tag/node.def
+++ b/templates/set/node.tag/node.def
@@ -1,3 +1,3 @@
help: Bash builtin set command
-allowed: echo -n --
+allowed:
run: builtin $*
diff --git a/templates/show/ntp/node.tag/node.def b/templates/show/ntp/node.tag/node.def
index 9ff0137..aa0dfaa 100644
--- a/templates/show/ntp/node.tag/node.def
+++ b/templates/show/ntp/node.tag/node.def
@@ -1,4 +1,3 @@
help: Show date and time of given NTP server
-allowed: sed 's/#.*//; s/^[^ \t]*[ \t]//; /^$/d' ${HOSTFILE:-/dev/null} ;
- echo --
+allowed: sed 's/#.*//; s/^[^ \t]*[ \t]//; /^$/d' ${HOSTFILE:-/dev/null}
run: ntpdate -q ${3:-ntp.vyatta.com}