diff options
author | John Southworth <john.southworth@vyatta.com> | 2012-01-28 12:25:52 -0800 |
---|---|---|
committer | John Southworth <john.southworth@vyatta.com> | 2012-02-03 09:08:44 -0800 |
commit | 9a06bd552126d69db40d30779cfc49404e42d761 (patch) | |
tree | 389bcb7f30dba43279e17666f0b1026670de285f /src | |
parent | 2f0e1c14a1d956c8915a56e09610c1f6ab8ea40c (diff) | |
download | vyatta-cfg-9a06bd552126d69db40d30779cfc49404e42d761.tar.gz vyatta-cfg-9a06bd552126d69db40d30779cfc49404e42d761.zip |
Add ability to differentiate between node types in help text
Diffstat (limited to 'src')
-rw-r--r-- | src/cli_shell_api.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
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), |