C-API: Add fromroot parameter to cli_show_common()
This commit is contained in:
parent
9091582087
commit
4730082d7b
4 changed files with 39 additions and 22 deletions
22
CHANGELOG.md
22
CHANGELOG.md
|
|
@ -53,19 +53,21 @@ Users may have to change how they access the system
|
||||||
### C/CLI-API changes on existing features
|
### C/CLI-API changes on existing features
|
||||||
Developers may need to change their code
|
Developers may need to change their code
|
||||||
|
|
||||||
|
* Add `fromroot` parameter to `cli_show_common()`
|
||||||
|
* `cli_show_common(...xpath...)` --> `cli_show_common(...xpath,0...)`
|
||||||
* Low-level message functions added `descr` argument for better logging
|
* Low-level message functions added `descr` argument for better logging
|
||||||
* In this way, message debugs in level 2 are more descriptive
|
* In this way, message debugs in level 2 are more descriptive
|
||||||
* The descr argument can be set to NULL for backward-compability, see the following translations:
|
* The descr argument can be set to NULL for backward-compability, see the following translations:
|
||||||
* clicon_rpc(s, ...) --> clicon_rpc(s, NULL, ...)
|
* `clicon_rpc(s, ...)` --> `clicon_rpc(s, NULL, ...)`
|
||||||
* clicon_rpc1(s, ...) --> clicon_rpc1(s, NULL, ...)
|
* `clicon_rpc1(s, ...)` --> `clicon_rpc1(s, NULL, ...)`
|
||||||
* clicon_msg_send(s, ...) --> clicon_msg_send(s, NULL, ...)
|
* `clicon_msg_send(s, ...)` --> `clicon_msg_send(s, NULL, ...)`
|
||||||
* clicon_msg_send1(s, ...) --> clicon_msg_send1(s, NULL, ...)
|
* `clicon_msg_send1(s, ...)` --> `clicon_msg_send1(s, NULL, ...)`
|
||||||
* clicon_msg_rcv(s, ...) --> clicon_msg_rcv(s, NULL, ...)
|
* `clicon_msg_rcv(s, ...)` --> `clicon_msg_rcv(s, NULL, ...)`
|
||||||
* clicon_msg_rcv1(s, ...) --> clicon_msg_rcv1(s, NULL, ...)
|
* `clicon_msg_rcv1(s, ...)` --> `clicon_msg_rcv1(s, NULL, ...)
|
||||||
* clicon_msg_notify_xml(h, s, ...) --> clicon_msg_notify_xml(h, s, NULL, ...)
|
* `clicon_msg_notify_xml(h, s, ...)` --> `clicon_msg_notify_xml(h, s, NULL, ...)`
|
||||||
* send_msg_reply(s, ...) --> send_msg_reply(s, NULL, ...)
|
* `send_msg_reply(s, ...)` --> `send_msg_reply(s, NULL, ...)`
|
||||||
* clixon_client_lock(s, ...) --> clixon_client_lock(s, NULL, ...)
|
* `clixon_client_lock(s, ...)` --> `clixon_client_lock(s, NULL, ...)`
|
||||||
* clixon_client_hello(s, ...) --> clixon_client_hello(s, NULL, ...)
|
* `clixon_client_hello(s, ...)` --> `clixon_client_hello(s, NULL, ...)`
|
||||||
|
|
||||||
* CLI pipe function: added arg to `pipe_tail_fn()`
|
* CLI pipe function: added arg to `pipe_tail_fn()`
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -474,6 +474,7 @@ show_yang(clicon_handle h,
|
||||||
* @param[in] extdefault with-defaults with propriatary extensions
|
* @param[in] extdefault with-defaults with propriatary extensions
|
||||||
* @param[in] prepend CLI prefix to prepend cli syntax, eg "set "
|
* @param[in] prepend CLI prefix to prepend cli syntax, eg "set "
|
||||||
* @param[in] xpath XPath
|
* @param[in] xpath XPath
|
||||||
|
* @param[in] fromroot If 0, display config from node of XPATH, if 1 display from root
|
||||||
* @param[in] nsc Namespace mapping for xpath
|
* @param[in] nsc Namespace mapping for xpath
|
||||||
* @param[in] skiptop If set, do not show object itself, only its children
|
* @param[in] skiptop If set, do not show object itself, only its children
|
||||||
*/
|
*/
|
||||||
|
|
@ -487,6 +488,7 @@ cli_show_common(clicon_handle h,
|
||||||
char *extdefault,
|
char *extdefault,
|
||||||
char *prepend,
|
char *prepend,
|
||||||
char *xpath,
|
char *xpath,
|
||||||
|
int fromroot,
|
||||||
cvec *nsc,
|
cvec *nsc,
|
||||||
int skiptop
|
int skiptop
|
||||||
)
|
)
|
||||||
|
|
@ -527,6 +529,8 @@ cli_show_common(clicon_handle h,
|
||||||
if (xml_defaults_nopresence(xt, 2) < 0)
|
if (xml_defaults_nopresence(xt, 2) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
if (fromroot)
|
||||||
|
xpath="/";
|
||||||
if (xpath_vec(xt, nsc, "%s", &vec, &veclen, xpath) < 0)
|
if (xpath_vec(xt, nsc, "%s", &vec, &veclen, xpath) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (veclen){
|
if (veclen){
|
||||||
|
|
@ -746,6 +750,7 @@ cli_show_config(clicon_handle h,
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
char *xpath = "/";
|
char *xpath = "/";
|
||||||
char *namespace = NULL;
|
char *namespace = NULL;
|
||||||
|
int fromroot = 0;
|
||||||
|
|
||||||
if (cvec_len(argv) < 2 || cvec_len(argv) > 8){
|
if (cvec_len(argv) < 2 || cvec_len(argv) > 8){
|
||||||
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <dbname> [<format><xpath> <namespace> <pretty> <state> <default> <prepend>]", cvec_len(argv));
|
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <dbname> [<format><xpath> <namespace> <pretty> <state> <default> <prepend>]", cvec_len(argv));
|
||||||
|
|
@ -783,7 +788,7 @@ cli_show_config(clicon_handle h,
|
||||||
}
|
}
|
||||||
if (cli_show_common(h, dbname, format, pretty, state,
|
if (cli_show_common(h, dbname, format, pretty, state,
|
||||||
withdefault, extdefault,
|
withdefault, extdefault,
|
||||||
prepend, xpath, nsc, 0) < 0)
|
prepend, xpath, fromroot, nsc, 0) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
|
@ -823,6 +828,7 @@ show_conf_xpath(clicon_handle h,
|
||||||
cg_var *cv;
|
cg_var *cv;
|
||||||
cvec *nsc = NULL;
|
cvec *nsc = NULL;
|
||||||
yang_stmt *yspec;
|
yang_stmt *yspec;
|
||||||
|
int fromroot = 0;
|
||||||
|
|
||||||
if (cvec_len(argv) != 1){
|
if (cvec_len(argv) != 1){
|
||||||
clicon_err(OE_PLUGIN, EINVAL, "Requires one element to be <dbname>");
|
clicon_err(OE_PLUGIN, EINVAL, "Requires one element to be <dbname>");
|
||||||
|
|
@ -849,7 +855,7 @@ show_conf_xpath(clicon_handle h,
|
||||||
}
|
}
|
||||||
if (cli_show_common(h, dbname, FORMAT_XML, 1, 0,
|
if (cli_show_common(h, dbname, FORMAT_XML, 1, 0,
|
||||||
NULL, NULL,
|
NULL, NULL,
|
||||||
NULL, xpath, nsc, 0) < 0)
|
NULL, xpath, fromroot, nsc, 0) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
|
@ -889,6 +895,7 @@ cli_show_version(clicon_handle h,
|
||||||
* <default> Retrieval mode: report-all, trim, explicit, report-all-tagged,
|
* <default> Retrieval mode: report-all, trim, explicit, report-all-tagged,
|
||||||
* NULL, report-all-tagged-default, report-all-tagged-strip (extended)
|
* NULL, report-all-tagged-default, report-all-tagged-strip (extended)
|
||||||
* <prepend> CLI prefix: prepend before cli syntax output
|
* <prepend> CLI prefix: prepend before cli syntax output
|
||||||
|
* <fromroot> true|false: Show from root
|
||||||
* @code
|
* @code
|
||||||
* clispec:
|
* clispec:
|
||||||
* show config @datamodelshow, cli_show_auto("candidate", "xml");
|
* show config @datamodelshow, cli_show_auto("candidate", "xml");
|
||||||
|
|
@ -929,9 +936,10 @@ cli_show_auto(clicon_handle h,
|
||||||
char *api_path_fmt01 = NULL;
|
char *api_path_fmt01 = NULL;
|
||||||
char *str;
|
char *str;
|
||||||
char *mtpoint = NULL;
|
char *mtpoint = NULL;
|
||||||
|
int fromroot = 0;
|
||||||
|
|
||||||
if (cvec_len(argv) < 2 || cvec_len(argv) > 8){
|
if (cvec_len(argv) < 2 || cvec_len(argv) > 9){
|
||||||
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected:: <api-path-fmt>* <database> [<format> <pretty> <state> <default> <prepend>]", cvec_len(argv));
|
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected:: <api-path-fmt>* <database> [<format> <pretty> <state> <default> <prepend> <fromroot>]", cvec_len(argv));
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
api_path_fmt = cv_string_get(cvec_i(argv, argc++));
|
api_path_fmt = cv_string_get(cvec_i(argv, argc++));
|
||||||
|
|
@ -962,6 +970,10 @@ cli_show_auto(clicon_handle h,
|
||||||
if (cvec_len(argv) > argc){
|
if (cvec_len(argv) > argc){
|
||||||
prepend = cv_string_get(cvec_i(argv, argc++));
|
prepend = cv_string_get(cvec_i(argv, argc++));
|
||||||
}
|
}
|
||||||
|
if (cvec_len(argv) > argc){
|
||||||
|
if (cli_show_option_bool(argv, argc++, &fromroot) < 0)
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
if ((yspec0 = clicon_dbspec_yang(h)) == NULL){
|
if ((yspec0 = clicon_dbspec_yang(h)) == NULL){
|
||||||
clicon_err(OE_FATAL, 0, "No DB_SPEC");
|
clicon_err(OE_FATAL, 0, "No DB_SPEC");
|
||||||
goto done;
|
goto done;
|
||||||
|
|
@ -985,7 +997,7 @@ cli_show_auto(clicon_handle h,
|
||||||
}
|
}
|
||||||
if (cli_show_common(h, dbname, format, pretty, state,
|
if (cli_show_common(h, dbname, format, pretty, state,
|
||||||
withdefault, extdefault,
|
withdefault, extdefault,
|
||||||
prepend, xpath, nsc, 0) < 0)
|
prepend, xpath, fromroot, nsc, 0) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
|
@ -1057,6 +1069,7 @@ cli_show_auto_mode(clicon_handle h,
|
||||||
cbuf *cbxpath = NULL;
|
cbuf *cbxpath = NULL;
|
||||||
cvec *nsc0 = NULL;
|
cvec *nsc0 = NULL;
|
||||||
cg_var *cv;
|
cg_var *cv;
|
||||||
|
int fromroot = 0;
|
||||||
|
|
||||||
if (cvec_len(argv) < 2 || cvec_len(argv) > 7){
|
if (cvec_len(argv) < 2 || cvec_len(argv) > 7){
|
||||||
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <database> [ <format> <pretty> <state> <default> <cli-prefix>]", cvec_len(argv));
|
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <database> [ <format> <pretty> <state> <default> <cli-prefix>]", cvec_len(argv));
|
||||||
|
|
@ -1122,7 +1135,7 @@ cli_show_auto_mode(clicon_handle h,
|
||||||
skiptop = (strcmp(xpath,"/") != 0);
|
skiptop = (strcmp(xpath,"/") != 0);
|
||||||
if (cli_show_common(h, dbname, format, pretty, state,
|
if (cli_show_common(h, dbname, format, pretty, state,
|
||||||
withdefault, extdefault,
|
withdefault, extdefault,
|
||||||
prepend, cbuf_get(cbxpath), nsc, skiptop) < 0)
|
prepend, cbuf_get(cbxpath), fromroot, nsc, skiptop) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ int expand_dbvar(void *h, char *name, cvec *cvv, cvec *argv,
|
||||||
int clixon_cli2file(clicon_handle h, FILE *f, cxobj *xn, char *prepend, clicon_output_cb *fn, int skiptop);
|
int clixon_cli2file(clicon_handle h, FILE *f, cxobj *xn, char *prepend, clicon_output_cb *fn, int skiptop);
|
||||||
|
|
||||||
/* cli_show.c: CLIgen new vector arg callbacks */
|
/* cli_show.c: CLIgen new vector arg callbacks */
|
||||||
int cli_show_common(clicon_handle h, char *db, enum format_enum format, int pretty, int state, char *withdefault, char *extdefault, char *prepend, char *xpath, cvec *nsc, int skiptop);
|
int cli_show_common(clicon_handle h, char *db, enum format_enum format, int pretty, int state, char *withdefault, char *extdefault, char *prepend, char *xpath, int fromroot, cvec *nsc, int skiptop);
|
||||||
|
|
||||||
int show_yang(clicon_handle h, cvec *vars, cvec *argv);
|
int show_yang(clicon_handle h, cvec *vars, cvec *argv);
|
||||||
int show_conf_xpath(clicon_handle h, cvec *cvv, cvec *argv);
|
int show_conf_xpath(clicon_handle h, cvec *cvv, cvec *argv);
|
||||||
|
|
|
||||||
|
|
@ -73,8 +73,8 @@ commit("Commit the changes"), cli_commit();
|
||||||
show("Show a particular state of the system"){
|
show("Show a particular state of the system"){
|
||||||
version("Show version"), cli_show_version("candidate", "text", "/");
|
version("Show version"), cli_show_version("candidate", "text", "/");
|
||||||
configuration("Show configuration"), cli_show_auto_mode("candidate", "xml", true, false);{
|
configuration("Show configuration"), cli_show_auto_mode("candidate", "xml", true, false);{
|
||||||
@|show, cli_show_auto_mode("candidate", "xml", true, false);
|
@|show, cli_show_auto_mode("candidate", "xml", true, false, "report-all");
|
||||||
@datamodelshow, cli_show_auto("candidate", "xml", true, false, "report-all");
|
@datamodelshow, cli_show_auto("candidate", "xml", true, false, "report-all", "set ", true);
|
||||||
}
|
}
|
||||||
autocli("Generated tree") @datamodelshow, cli_show_auto("candidate", "xml", true, false, "report-all");
|
autocli("Generated tree") @datamodelshow, cli_show_auto("candidate", "xml", true, false, "report-all");
|
||||||
}
|
}
|
||||||
|
|
@ -126,8 +126,7 @@ expectpart "$($clixon_cli -1 -f $cfg commit)" 0 "^$"
|
||||||
|
|
||||||
# 1. Multiple pipe files: pipe_common + pipe_show where the latter is a superset
|
# 1. Multiple pipe files: pipe_common + pipe_show where the latter is a superset
|
||||||
new "multiple files: show menu contains common items"
|
new "multiple files: show menu contains common items"
|
||||||
echo "$clixon_cli -1 -f $cfg show config \| count"
|
expectpart "$($clixon_cli -1 -f $cfg show configuration \| count)" 0 10
|
||||||
expectpart "$($clixon_cli -1 -f $cfg show config \| count)" 0 10
|
|
||||||
|
|
||||||
# 2. Implicit pipe and explicit in same file where explicit overrides
|
# 2. Implicit pipe and explicit in same file where explicit overrides
|
||||||
new "Implicit default command"
|
new "Implicit default command"
|
||||||
|
|
@ -141,7 +140,7 @@ new "sub-tree default implicit"
|
||||||
expectpart "$(echo "set table \| ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 count --not-- showas
|
expectpart "$(echo "set table \| ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 count --not-- showas
|
||||||
|
|
||||||
new "sub-tree explicit"
|
new "sub-tree explicit"
|
||||||
expectpart "$(echo "show config table \| ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 count showas
|
expectpart "$(echo "show configuration table \| ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 count showas
|
||||||
|
|
||||||
# History error: second command affected by first
|
# History error: second command affected by first
|
||||||
# show configuration | count is OK
|
# show configuration | count is OK
|
||||||
|
|
@ -159,6 +158,9 @@ EOF
|
||||||
new "Implicit followed by explicit"
|
new "Implicit followed by explicit"
|
||||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "<value>a</value>" --not-- "Unknown command"
|
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "<value>a</value>" --not-- "Unknown command"
|
||||||
|
|
||||||
|
new "subtree two level show"
|
||||||
|
expectpart "$(echo "show configuration table parameter \| showas xml" | $clixon_cli -f $cfg 2> /dev/null)" 0 "<table xmlns=\"urn:example:clixon\">" "<name>x</name>"
|
||||||
|
|
||||||
if [ $BE -ne 0 ]; then
|
if [ $BE -ne 0 ]; then
|
||||||
new "Kill backend"
|
new "Kill backend"
|
||||||
# Check if premature kill
|
# Check if premature kill
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue