summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Southworth <john.southworth@vyatta.com>2012-01-28 12:25:52 -0800
committerJohn Southworth <john.southworth@vyatta.com>2012-02-03 09:08:44 -0800
commit9a06bd552126d69db40d30779cfc49404e42d761 (patch)
tree389bcb7f30dba43279e17666f0b1026670de285f
parent2f0e1c14a1d956c8915a56e09610c1f6ab8ea40c (diff)
downloadvyatta-cfg-9a06bd552126d69db40d30779cfc49404e42d761.tar.gz
vyatta-cfg-9a06bd552126d69db40d30779cfc49404e42d761.zip
Add ability to differentiate between node types in help text
-rwxr-xr-xetc/bash_completion.d/vyatta-cfg24
-rw-r--r--functions/interpreter/vyatta-cfg-run28
-rw-r--r--src/cli_shell_api.cpp85
3 files changed, 119 insertions, 18 deletions
diff --git a/etc/bash_completion.d/vyatta-cfg b/etc/bash_completion.d/vyatta-cfg
index a32b8eb..cbec48b 100755
--- a/etc/bash_completion.d/vyatta-cfg
+++ b/etc/bash_completion.d/vyatta-cfg
@@ -459,13 +459,29 @@ get_help_text ()
{
vyatta_help_text="\\nPossible completions:"
for (( idx = 0; idx < ${#_get_help_text_items[@]}; idx++ )); do
- vyatta_help_text+="\\n\\x20\\x20"
- if [ ${#_get_help_text_items[idx]} -lt 6 ]; then
+ vyatta_help_text+="\\n"
+ if (( ${#COMP_WORDS[@]} < 2 )) ||
+ [[ $COMP_CWORD -eq 0 ]]; then
+ vyatta_help_text+="\\x20\\x20\\x20"
+ else
+ if [[ ${#_get_help_text_items[@]} == 1 ]]; then
+ local nodeType=$(cli-shell-api getNodeType ${api_args[@]:1:${comp_cword}})
+ else
+ local nodeType=$(cli-shell-api getNodeType ${api_args[@]:1:${comp_cword}} ${_get_help_text_items[idx]})
+ fi
+ case "$nodeType" in
+ tag) vyatta_help_text+="+> " ;;
+ non-leaf) vyatta_help_text+=" > " ;;
+ multi) vyatta_help_text+="+ " ;;
+ *) vyatta_help_text+=" " ;;
+ esac
+ fi
+ if [ ${#_get_help_text_items[idx]} -lt 5 ]; then
vyatta_help_text+="${_get_help_text_items[idx]}\\t\\t"
- elif [ ${#_get_help_text_items[idx]} -lt 14 ]; then
+ elif [ ${#_get_help_text_items[idx]} -lt 13 ]; then
vyatta_help_text+="${_get_help_text_items[idx]}\\t"
else
- vyatta_help_text+="${_get_help_text_items[idx]}\\n\\x20\\x20\\t\\t"
+ vyatta_help_text+="${_get_help_text_items[idx]}\\n\\x20\\x20\\x20\\t\\t"
fi
vyatta_help_text+="${_get_help_text_helps[idx]}"
done
diff --git a/functions/interpreter/vyatta-cfg-run b/functions/interpreter/vyatta-cfg-run
index 25217b2..7558ffa 100644
--- a/functions/interpreter/vyatta-cfg-run
+++ b/functions/interpreter/vyatta-cfg-run
@@ -376,9 +376,9 @@ vyatta_cfg_validate_cmd ()
local -a _get_help_text_helps=( "${_cli_shell_api_hstrs[@]}" )
local vyatta_help_text=''
if [[ $opath == '' ]]; then
- echo -ne "\n Configuration path: [$arg] is ambiguous\n"
+ echo -ne "\n Configuration path: [$arg] is ambiguous\n" >&2
else
- echo -ne "\n Configuration path: $opath [$arg] is ambiguous\n"
+ echo -ne "\n Configuration path: $opath [$arg] is ambiguous\n" >&2
fi
get_help_text
echo -e "$vyatta_help_text\n" | sed 's/^P/ P/'
@@ -386,9 +386,9 @@ vyatta_cfg_validate_cmd ()
break
else
if [[ $opath == '' ]]; then
- echo -ne "\n Configuration path: [$arg] is not valid\n ${cmd^} failed\n\n"
+ echo -ne "\n Configuration path: [$arg] is not valid\n ${cmd^} failed\n\n" >&2
else
- echo -ne "\n Configuration path: $opath [$arg] is not valid\n ${cmd^} failed\n\n"
+ echo -ne "\n Configuration path: $opath [$arg] is not valid\n ${cmd^} failed\n\n" >&2
fi
break
fi
@@ -416,7 +416,7 @@ vyatta_config_copy ()
vyatta_config_expand_compwords "${param2[@]}"
param2=( "${expanded_api_args[@]}" )
if [[ "${args[3]}" != "to" ]]; then
- echo -ne "\n Invalid command: $cmd ${param1[@]:1} ${args[3]} ${param2[@]:1}\n\n"
+ echo -ne "\n Invalid command: $cmd ${param1[@]:1} ${args[3]} ${param2[@]:1}\n\n" >&2
elif cli-shell-api validateTmplPath -- ${editlvl[*]} "${param1[@]:1}" &&
cli-shell-api validateTmplPath -- ${editlvl[*]} "${param2[@]:1}" ; then
cmd="/opt/vyatta/sbin/my_$cmd"
@@ -430,23 +430,23 @@ vyatta_config_copy ()
vyatta_cli_shell_api getCompletionEnv $cmd ${param1[1]}
if [[ "${#_cli_shell_api_comp_values[@]}" != "1"
&& "${#_cli_shell_api_comp_values[@]}" != "0" ]]; then
- echo -ne "\n Ambiguous command: $cmd [${param1[1]}]\n"
- echo -ne "\n Possible completions: ${_cli_shell_api_comp_values[@]}\n\n"
+ echo -ne "\n Ambiguous command: $cmd [${param1[1]}]\n" >&2
+ echo -ne "\n Possible completions: ${_cli_shell_api_comp_values[@]}\n\n" >&2
else
- echo -ne "\n Invalid command: $cmd [${param1[1]}]\n\n"
+ echo -ne "\n Invalid command: $cmd [${param1[1]}]\n\n" >&2
fi
elif ! cli-shell-api validateTmplPath -- ${editlvl[*]} "${param1[@]:2}"; then
_cli_shell_api_comp_values=()
vyatta_cli_shell_api getCompletionEnv $cmd "${param2[1]}"
if [[ "${#_cli_shell_api_comp_values[@]}" != "1"
&& "${#_cli_shell_api_comp_values[@]}" != "0" ]]; then
- echo -ne "\n Ambiguous command: $cmd ${param2[@]:1} to [${param2[1]}]\n"
- echo -ne "\n Possible completions: ${_cli_shell_api_comp_values[@]}\n\n"
+ echo -ne "\n Ambiguous command: $cmd ${param2[@]:1} to [${param2[1]}]\n" >&2
+ echo -ne "\n Possible completions: ${_cli_shell_api_comp_values[@]}\n\n" >&2
else
- echo -ne "\n Invalid command: $cmd ${param1[@]:1} to [${param2[1]}]\n\n"
+ echo -ne "\n Invalid command: $cmd ${param1[@]:1} to [${param2[1]}]\n\n" >&2
fi
else
- echo -ne "\n Invalid command: $cmd ${param1[@]:1} to ${param2[@]:1}\n\n"
+ echo -ne "\n Invalid command: $cmd ${param1[@]:1} to ${param2[@]:1}\n\n" >&2
fi
fi
}
@@ -521,10 +521,10 @@ vyatta_cfg_run ()
# not a fix we need to look at why the readline library
# is getting confused on paged help text.
if [[ "${#filtered_cmds[@]}" == "0" ]]; then
- echo -ne "\n Invalid command: [$cmd]\n\n"
+ echo -ne "\n Invalid command: [$cmd]\n\n" >&2
return 1
elif [[ "${#filtered_cmds[@]}" != "1" && "$found" == "1" ]]; then
- echo -ne "\n Ambiguous command: [$cmd]\n"
+ echo -ne "\n Ambiguous command: [$cmd]\n" >&2
local -a fitems=()
local -a fstrs=()
local -a _get_help_text_items=( "${_vyatta_cfg_cmds[@]}" )
diff --git a/src/cli_shell_api.cpp b/src/cli_shell_api.cpp
index 18d3db7..aa8eafd 100644
--- a/src/cli_shell_api.cpp
+++ b/src/cli_shell_api.cpp
@@ -23,6 +23,7 @@
#include <cli_cstore.h>
#include <cstore/cstore.hpp>
+#include <cstore/util.hpp>
#include <cnode/cnode.hpp>
#include <cnode/cnode-algorithm.hpp>
#include <commit/commit-algorithm.hpp>
@@ -228,6 +229,84 @@ existsEffective(Cstore& cstore, const Cpath& args)
exit(cstore.cfgPathEffective(args) ? 0 : 1);
}
+/* isMulti */
+static void
+isMulti(Cstore& cstore, const Cpath& args)
+{
+ MapT<string, string> tmap;
+ cstore.getParsedTmpl(args, tmap, 0);
+ string multi = tmap["multi"];
+ exit((multi == "1") ? 0 : 1);
+}
+
+/* isTag */
+static void
+isTag(Cstore& cstore, const Cpath& args)
+{
+ MapT<string, string> tmap;
+ cstore.getParsedTmpl(args, tmap, 0);
+ string tag = tmap["tag"];
+ exit((tag == "1") ? 0 : 1);
+}
+
+/* isValue */
+static void
+isValue(Cstore& cstore, const Cpath& args)
+{
+ MapT<string, string> tmap;
+ cstore.getParsedTmpl(args, tmap, 0);
+ string is_value = tmap["is_value"];
+ exit((is_value == "1") ? 0 : 1);
+}
+
+/* isLeaf */
+static void
+isLeaf(Cstore& cstore, const Cpath& args)
+{
+ MapT<string, string> tmap;
+ bool is_leaf_typeless = false;
+ tmap["type"] = "";
+ cstore.getParsedTmpl(args, tmap, 0);
+ string is_value = tmap["is_value"];
+ string tag = tmap["tag"];
+ string type = tmap["type"];
+ vector<string> tcnodes;
+ cstore.tmplGetChildNodes(args, tcnodes);
+ if (tcnodes.size() == 0) {
+ // typeless leaf node
+ is_leaf_typeless = true;
+ }
+ exit(((is_value != "1") && (tag != "1") && (type != "" || is_leaf_typeless)) ? 0 : 1);
+}
+
+static void getNodeType(Cstore& cstore, const Cpath& args) {
+ MapT<string, string> tmap;
+ bool is_leaf_typeless = false;
+ tmap["type"] = "";
+ cstore.getParsedTmpl(args, tmap, 0);
+ string is_value = tmap["is_value"];
+ string tag = tmap["tag"];
+ string type = tmap["type"];
+ string multi = tmap["multi"];
+ vector<string> tcnodes;
+ cstore.tmplGetChildNodes(args, tcnodes);
+ if (tcnodes.size() == 0) {
+ // typeless leaf node
+ is_leaf_typeless = true;
+ }
+ if (tag == "1") {
+ printf("tag");
+ } else if (!((is_value != "1") && (tag != "1") && (type != "" || is_leaf_typeless))) {
+ printf("non-leaf");
+ } else if (multi == "1") {
+ printf("multi");
+ } else {
+ printf("leaf");
+ }
+ exit(0);
+
+}
+
/* same as listNodes() in Perl API.
*
* outputs a string representing multiple nodes. this string MUST be
@@ -579,6 +658,12 @@ static OpT ops[] = {
OP(listActiveNodes, -1, NULL, -1, NULL, false),
OP(listEffectiveNodes, -1, NULL, 1, "Must specify config path", false),
+ OP(isMulti, -1, NULL, 1, "Must specify config path", false),
+ OP(isTag, -1, NULL, 1, "Must specify config path", false),
+ OP(isLeaf, -1, NULL, 1, "Must specify config path", false),
+ OP(isValue, -1, NULL, 1, "Must specify config path", false),
+ OP(getNodeType, -1, NULL, 1, "Must specify config path", false),
+
OP(returnValue, -1, NULL, 1, "Must specify config path", false),
OP(returnActiveValue, -1, NULL, 1, "Must specify config path", false),
OP(returnEffectiveValue, -1, NULL, 1, "Must specify config path", false),