Skip to content

Commit

Permalink
C-API: Add fromroot parameter to cli_show_common()
Browse files Browse the repository at this point in the history
  • Loading branch information
olofhagsand committed Sep 12, 2023
1 parent 9091582 commit 4730082
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 22 deletions.
22 changes: 12 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,21 @@ Users may have to change how they access the system
### C/CLI-API changes on existing features
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
* 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:
* clicon_rpc(s, ...) --> clicon_rpc(s, NULL, ...)
* clicon_rpc1(s, ...) --> clicon_rpc1(s, NULL, ...)
* clicon_msg_send(s, ...) --> clicon_msg_send(s, NULL, ...)
* clicon_msg_send1(s, ...) --> clicon_msg_send1(s, NULL, ...)
* clicon_msg_rcv(s, ...) --> clicon_msg_rcv(s, NULL, ...)
* clicon_msg_rcv1(s, ...) --> clicon_msg_rcv1(s, NULL, ...)
* clicon_msg_notify_xml(h, s, ...) --> clicon_msg_notify_xml(h, s, NULL, ...)
* send_msg_reply(s, ...) --> send_msg_reply(s, NULL, ...)
* clixon_client_lock(s, ...) --> clixon_client_lock(s, NULL, ...)
* clixon_client_hello(s, ...) --> clixon_client_hello(s, NULL, ...)
* `clicon_rpc(s, ...)` --> `clicon_rpc(s, NULL, ...)`
* `clicon_rpc1(s, ...)` --> `clicon_rpc1(s, NULL, ...)`
* `clicon_msg_send(s, ...)` --> `clicon_msg_send(s, NULL, ...)`
* `clicon_msg_send1(s, ...)` --> `clicon_msg_send1(s, NULL, ...)`
* `clicon_msg_rcv(s, ...)` --> `clicon_msg_rcv(s, NULL, ...)`
* `clicon_msg_rcv1(s, ...)` --> `clicon_msg_rcv1(s, NULL, ...)
* `clicon_msg_notify_xml(h, s, ...)` --> `clicon_msg_notify_xml(h, s, NULL, ...)`
* `send_msg_reply(s, ...)` --> `send_msg_reply(s, NULL, ...)`
* `clixon_client_lock(s, ...)` --> `clixon_client_lock(s, NULL, ...)`
* `clixon_client_hello(s, ...)` --> `clixon_client_hello(s, NULL, ...)`

* CLI pipe function: added arg to `pipe_tail_fn()`

Expand Down
25 changes: 19 additions & 6 deletions apps/cli/cli_show.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ show_yang(clicon_handle h,
* @param[in] extdefault with-defaults with propriatary extensions
* @param[in] prepend CLI prefix to prepend cli syntax, eg "set "
* @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] skiptop If set, do not show object itself, only its children
*/
Expand All @@ -487,6 +488,7 @@ cli_show_common(clicon_handle h,
char *extdefault,
char *prepend,
char *xpath,
int fromroot,
cvec *nsc,
int skiptop
)
Expand Down Expand Up @@ -527,6 +529,8 @@ cli_show_common(clicon_handle h,
if (xml_defaults_nopresence(xt, 2) < 0)
goto done;
}
if (fromroot)
xpath="/";
if (xpath_vec(xt, nsc, "%s", &vec, &veclen, xpath) < 0)
goto done;
if (veclen){
Expand Down Expand Up @@ -746,6 +750,7 @@ cli_show_config(clicon_handle h,
int argc = 0;
char *xpath = "/";
char *namespace = NULL;
int fromroot = 0;

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));
Expand Down Expand Up @@ -783,7 +788,7 @@ cli_show_config(clicon_handle h,
}
if (cli_show_common(h, dbname, format, pretty, state,
withdefault, extdefault,
prepend, xpath, nsc, 0) < 0)
prepend, xpath, fromroot, nsc, 0) < 0)
goto done;
retval = 0;
done:
Expand Down Expand Up @@ -823,6 +828,7 @@ show_conf_xpath(clicon_handle h,
cg_var *cv;
cvec *nsc = NULL;
yang_stmt *yspec;
int fromroot = 0;

if (cvec_len(argv) != 1){
clicon_err(OE_PLUGIN, EINVAL, "Requires one element to be <dbname>");
Expand All @@ -849,7 +855,7 @@ show_conf_xpath(clicon_handle h,
}
if (cli_show_common(h, dbname, FORMAT_XML, 1, 0,
NULL, NULL,
NULL, xpath, nsc, 0) < 0)
NULL, xpath, fromroot, nsc, 0) < 0)
goto done;
retval = 0;
done:
Expand Down Expand Up @@ -889,6 +895,7 @@ cli_show_version(clicon_handle h,
* <default> Retrieval mode: report-all, trim, explicit, report-all-tagged,
* NULL, report-all-tagged-default, report-all-tagged-strip (extended)
* <prepend> CLI prefix: prepend before cli syntax output
* <fromroot> true|false: Show from root
* @code
* clispec:
* show config @datamodelshow, cli_show_auto("candidate", "xml");
Expand Down Expand Up @@ -929,9 +936,10 @@ cli_show_auto(clicon_handle h,
char *api_path_fmt01 = NULL;
char *str;
char *mtpoint = NULL;
int fromroot = 0;

if (cvec_len(argv) < 2 || cvec_len(argv) > 8){
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected:: <api-path-fmt>* <database> [<format> <pretty> <state> <default> <prepend>]", cvec_len(argv));
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> <fromroot>]", cvec_len(argv));
goto done;
}
api_path_fmt = cv_string_get(cvec_i(argv, argc++));
Expand Down Expand Up @@ -962,6 +970,10 @@ cli_show_auto(clicon_handle h,
if (cvec_len(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){
clicon_err(OE_FATAL, 0, "No DB_SPEC");
goto done;
Expand All @@ -985,7 +997,7 @@ cli_show_auto(clicon_handle h,
}
if (cli_show_common(h, dbname, format, pretty, state,
withdefault, extdefault,
prepend, xpath, nsc, 0) < 0)
prepend, xpath, fromroot, nsc, 0) < 0)
goto done;
retval = 0;
done:
Expand Down Expand Up @@ -1057,6 +1069,7 @@ cli_show_auto_mode(clicon_handle h,
cbuf *cbxpath = NULL;
cvec *nsc0 = NULL;
cg_var *cv;
int fromroot = 0;

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));
Expand Down Expand Up @@ -1122,7 +1135,7 @@ cli_show_auto_mode(clicon_handle h,
skiptop = (strcmp(xpath,"/") != 0);
if (cli_show_common(h, dbname, format, pretty, state,
withdefault, extdefault,
prepend, cbuf_get(cbxpath), nsc, skiptop) < 0)
prepend, cbuf_get(cbxpath), fromroot, nsc, skiptop) < 0)
goto done;
retval = 0;
done:
Expand Down
2 changes: 1 addition & 1 deletion apps/cli/clixon_cli_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/* 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_conf_xpath(clicon_handle h, cvec *cvv, cvec *argv);
Expand Down
12 changes: 7 additions & 5 deletions test/test_cli_pipe_multi.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ commit("Commit the changes"), cli_commit();
show("Show a particular state of the system"){
version("Show version"), cli_show_version("candidate", "text", "/");
configuration("Show configuration"), cli_show_auto_mode("candidate", "xml", true, false);{
@|show, cli_show_auto_mode("candidate", "xml", true, false);
@datamodelshow, cli_show_auto("candidate", "xml", true, false, "report-all");
@|show, cli_show_auto_mode("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");
}
Expand Down Expand Up @@ -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
new "multiple files: show menu contains common items"
echo "$clixon_cli -1 -f $cfg show config \| count"
expectpart "$($clixon_cli -1 -f $cfg show config \| count)" 0 10
expectpart "$($clixon_cli -1 -f $cfg show configuration \| count)" 0 10

# 2. Implicit pipe and explicit in same file where explicit overrides
new "Implicit default command"
Expand All @@ -141,7 +140,7 @@ new "sub-tree default implicit"
expectpart "$(echo "set table \| ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 count --not-- showas

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
# show configuration | count is OK
Expand All @@ -159,6 +158,9 @@ EOF
new "Implicit followed by explicit"
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
new "Kill backend"
# Check if premature kill
Expand Down

0 comments on commit 4730082

Please sign in to comment.