- fix autocli modes error of empty type
- rename tests test_cli_auto -> test_autocli
This commit is contained in:
parent
e0bcca5405
commit
9b99d63411
8 changed files with 48 additions and 43 deletions
|
|
@ -316,7 +316,7 @@ cli_xml2txt(cxobj *xn,
|
||||||
/*! Enter a CLI edit mode
|
/*! Enter a CLI edit mode
|
||||||
* @param[in] h CLICON handle
|
* @param[in] h CLICON handle
|
||||||
* @param[in] cvv Vector of variables from CLIgen command-line
|
* @param[in] cvv Vector of variables from CLIgen command-line
|
||||||
* @param[in] argv Vector oif user-supplied keywords
|
* @param[in] argv Vector of user-supplied keywords
|
||||||
* Format of argv:
|
* Format of argv:
|
||||||
* <api_path_fmt> Generated API PATH (This is where we are in the tree)
|
* <api_path_fmt> Generated API PATH (This is where we are in the tree)
|
||||||
* <treename> Name of generated cligen parse-tree, eg "datamodel"
|
* <treename> Name of generated cligen parse-tree, eg "datamodel"
|
||||||
|
|
|
||||||
|
|
@ -135,11 +135,11 @@ cli_expand_var_generate(clicon_handle h,
|
||||||
{
|
{
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
char *api_path_fmt = NULL;
|
char *api_path_fmt = NULL;
|
||||||
int exist = 0;
|
int hideext = 0;
|
||||||
|
|
||||||
if (yang_extension_value(ys, "hide", CLIXON_AUTOCLI_NS, &exist, NULL) < 0)
|
if (yang_extension_value(ys, "hide", CLIXON_AUTOCLI_NS, &hideext, NULL) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (exist) {
|
if (hideext) {
|
||||||
retval = 1;
|
retval = 1;
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
@ -669,7 +669,6 @@ yang2cli_var(clicon_handle h,
|
||||||
&options, &cvv, patterns, NULL, &fraction_digits) < 0)
|
&options, &cvv, patterns, NULL, &fraction_digits) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
restype = yang_argument_get(yrestype);
|
restype = yang_argument_get(yrestype);
|
||||||
|
|
||||||
if (strcmp(restype, "empty") == 0)
|
if (strcmp(restype, "empty") == 0)
|
||||||
goto ok;
|
goto ok;
|
||||||
if (clicon_type2cv(origtype, restype, yreferred, &cvtype) < 0)
|
if (clicon_type2cv(origtype, restype, yreferred, &cvtype) < 0)
|
||||||
|
|
@ -757,14 +756,14 @@ yang2cli_leaf(clicon_handle h,
|
||||||
int key_leaf,
|
int key_leaf,
|
||||||
cbuf *cb)
|
cbuf *cb)
|
||||||
{
|
{
|
||||||
yang_stmt *yd; /* description */
|
yang_stmt *yd; /* description */
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
char *helptext = NULL;
|
char *helptext = NULL;
|
||||||
char *s;
|
char *s;
|
||||||
|
|
||||||
int extralevel = 0;
|
|
||||||
autocli_listkw_t listkw;
|
autocli_listkw_t listkw;
|
||||||
int exist = 0;
|
int hideext = 0;
|
||||||
|
int extralevel = 0;
|
||||||
|
yang_stmt *yrestype; /* resolved type */
|
||||||
|
|
||||||
/* description */
|
/* description */
|
||||||
if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){
|
if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){
|
||||||
|
|
@ -776,6 +775,13 @@ yang2cli_leaf(clicon_handle h,
|
||||||
*s = '\0';
|
*s = '\0';
|
||||||
}
|
}
|
||||||
cprintf(cb, "%*s", level*3, "");
|
cprintf(cb, "%*s", level*3, "");
|
||||||
|
extralevel = !key_leaf;
|
||||||
|
/* Called a second time in yang2cli_var, room for optimization */
|
||||||
|
if (yang_type_get(ys, NULL, &yrestype,
|
||||||
|
NULL, NULL, NULL, NULL, NULL) < 0)
|
||||||
|
goto done;
|
||||||
|
if (strcmp(yang_argument_get(yrestype), "empty") == 0 && extralevel)
|
||||||
|
extralevel = 0;
|
||||||
if (autocli_list_keyword(h, &listkw) < 0)
|
if (autocli_list_keyword(h, &listkw) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (listkw == AUTOCLI_LISTKW_ALL ||
|
if (listkw == AUTOCLI_LISTKW_ALL ||
|
||||||
|
|
@ -783,16 +789,30 @@ yang2cli_leaf(clicon_handle h,
|
||||||
cprintf(cb, "%s", yang_argument_get(ys));
|
cprintf(cb, "%s", yang_argument_get(ys));
|
||||||
yang2cli_helptext(cb, helptext);
|
yang2cli_helptext(cb, helptext);
|
||||||
cprintf(cb, " ");
|
cprintf(cb, " ");
|
||||||
if (yang_extension_value(ys, "hide", CLIXON_AUTOCLI_NS, &exist, NULL) < 0)
|
if (yang_extension_value(ys, "hide", CLIXON_AUTOCLI_NS, &hideext, NULL) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (exist){
|
if (hideext)
|
||||||
cprintf(cb, ", hide{");
|
cprintf(cb, ", hide"); /* XXX ensure always { */
|
||||||
extralevel = 1;
|
if (extralevel){
|
||||||
|
if (callback){
|
||||||
|
if (cli_callback_generate(h, ys, cb) < 0)
|
||||||
|
goto done;
|
||||||
|
cprintf(cb, ";\n");
|
||||||
|
}
|
||||||
|
cprintf(cb, "{"); /* termleaf label + extra level around leaf */
|
||||||
}
|
}
|
||||||
if (yang2cli_var(h, ys, ys, helptext, cb) < 0)
|
if (yang2cli_var(h, ys, ys, helptext, cb) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
if (extralevel){
|
||||||
|
if (callback){
|
||||||
|
if (cli_callback_generate(h, ys, cb) < 0)
|
||||||
|
goto done;
|
||||||
|
cprintf(cb, ";\n");
|
||||||
|
}
|
||||||
|
cprintf(cb, "{"); /* termleaf label */
|
||||||
|
}
|
||||||
if (yang2cli_var(h, ys, ys, helptext, cb) < 0)
|
if (yang2cli_var(h, ys, ys, helptext, cb) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
@ -828,7 +848,6 @@ yang2cli_container(clicon_handle h,
|
||||||
char *helptext = NULL;
|
char *helptext = NULL;
|
||||||
char *s;
|
char *s;
|
||||||
int compress = 0;
|
int compress = 0;
|
||||||
int hide_oc = 0;
|
|
||||||
yang_stmt *ymod = NULL;
|
yang_stmt *ymod = NULL;
|
||||||
int exist = 0;
|
int exist = 0;
|
||||||
|
|
||||||
|
|
@ -840,7 +859,7 @@ yang2cli_container(clicon_handle h,
|
||||||
*/
|
*/
|
||||||
if (autocli_compress(h, ys, &compress) < 0)
|
if (autocli_compress(h, ys, &compress) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (!compress && hide_oc == 0){
|
if (!compress){
|
||||||
cprintf(cb, "%*s%s", level*3, "", yang_argument_get(ys));
|
cprintf(cb, "%*s%s", level*3, "", yang_argument_get(ys));
|
||||||
if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){
|
if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){
|
||||||
if ((helptext = strdup(yang_argument_get(yd))) == NULL){
|
if ((helptext = strdup(yang_argument_get(yd))) == NULL){
|
||||||
|
|
@ -865,7 +884,7 @@ yang2cli_container(clicon_handle h,
|
||||||
while ((yc = yn_each(ys, yc)) != NULL)
|
while ((yc = yn_each(ys, yc)) != NULL)
|
||||||
if (yang2cli_stmt(h, yc, level+1, cb) < 0)
|
if (yang2cli_stmt(h, yc, level+1, cb) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
if (!compress && hide_oc == 0)
|
if (!compress)
|
||||||
cprintf(cb, "%*s}\n", level*3, "");
|
cprintf(cb, "%*s}\n", level*3, "");
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
|
@ -1097,7 +1116,6 @@ cvec_add_name(cvec *cvv,
|
||||||
|
|
||||||
/*! Recursive post processing of generated cligen parsetree: populate with co_cvec labels
|
/*! Recursive post processing of generated cligen parsetree: populate with co_cvec labels
|
||||||
*
|
*
|
||||||
|
|
||||||
* This function adds labels to the generated CLIgen tree using YANG as follows:
|
* This function adds labels to the generated CLIgen tree using YANG as follows:
|
||||||
* These labels can be filtered when applying them with the @treeref, @add:<label> syntax.
|
* These labels can be filtered when applying them with the @treeref, @add:<label> syntax.
|
||||||
* (terminal entry means eg "a ;" where ; is an "empty" child of "a" representing a terminal)
|
* (terminal entry means eg "a ;" where ; is an "empty" child of "a" representing a terminal)
|
||||||
|
|
@ -1125,7 +1143,6 @@ cvec_add_name(cvec *cvv,
|
||||||
* for y in modules
|
* for y in modules
|
||||||
* for co in top-level commands
|
* for co in top-level commands
|
||||||
* if yc = find(y,co)=NULL continue; <----
|
* if yc = find(y,co)=NULL continue; <----
|
||||||
* Also adds an empty node under LIST which is a kludge, it cannot be expressed in the CLIgen syntax
|
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
yang2cli_post(clicon_handle h,
|
yang2cli_post(clicon_handle h,
|
||||||
|
|
@ -1187,18 +1204,6 @@ yang2cli_post(clicon_handle h,
|
||||||
switch (yang_keyword_get(yc)){
|
switch (yang_keyword_get(yc)){
|
||||||
case Y_LEAF:
|
case Y_LEAF:
|
||||||
case Y_LEAF_LIST:
|
case Y_LEAF_LIST:
|
||||||
/* add empty show
|
|
||||||
regular should have ; on last
|
|
||||||
other ; should be marked as ;
|
|
||||||
Only last key */
|
|
||||||
if (co->co_type == CO_COMMAND && !co_terminal(co, NULL)){
|
|
||||||
cg_obj *coe;
|
|
||||||
if ((coe = co_new(NULL, co)) == NULL) {
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
coe->co_type = CO_EMPTY;
|
|
||||||
coe = co_insert(co_pt_get(co), coe);
|
|
||||||
}
|
|
||||||
/* XXX move to next recursion level ? */
|
/* XXX move to next recursion level ? */
|
||||||
if (!yciskey)
|
if (!yciskey)
|
||||||
for (j = 0; j<pt_len_get(co_pt_get(co)); j++){
|
for (j = 0; j<pt_len_get(co_pt_get(co)); j++){
|
||||||
|
|
|
||||||
|
|
@ -145,6 +145,15 @@ EOF
|
||||||
new "edit table parameter a; show"
|
new "edit table parameter a; show"
|
||||||
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "/clixon-example:table/parameter=a/>" "<name>a</name><value>42</value>" --not-- '<table xmlns="urn:example:clixon">' "<parameter>"
|
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "/clixon-example:table/parameter=a/>" "<name>a</name><value>42</value>" --not-- '<table xmlns="urn:example:clixon">' "<parameter>"
|
||||||
|
|
||||||
|
cat <<EOF > $fin
|
||||||
|
edit table
|
||||||
|
edit parameter
|
||||||
|
edit a
|
||||||
|
show config xml
|
||||||
|
EOF
|
||||||
|
new "edit table; edit parameter; edit a; show"
|
||||||
|
expectpart "$(cat $fin | $clixon_cli -f $cfg 2>&1)" 0 "<name>a</name><value>42</value>" --not-- '<table xmlns="urn:example:clixon">' "<parameter>"
|
||||||
|
|
||||||
cat <<EOF > $fin
|
cat <<EOF > $fin
|
||||||
edit table
|
edit table
|
||||||
edit parameter a
|
edit parameter a
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# Tests for using the auto cli.
|
# Tests for using the auto cli.
|
||||||
# In particular setting a config, displaying as cli commands and reconfigure it
|
# In particular setting a config, displaying as cli commands and reconfigure it
|
||||||
|
|
@ -25,8 +24,6 @@ else
|
||||||
mkdir $clidir
|
mkdir $clidir
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Use yang in example
|
|
||||||
|
|
||||||
if [ ! -d "$OPENCONFIG" ]; then
|
if [ ! -d "$OPENCONFIG" ]; then
|
||||||
# err "Hmm Openconfig dir does not seem to exist, try git clone https://github.com/openconfig/public?"
|
# err "Hmm Openconfig dir does not seem to exist, try git clone https://github.com/openconfig/public?"
|
||||||
echo "...skipped: OPENCONFIG not set"
|
echo "...skipped: OPENCONFIG not set"
|
||||||
|
|
@ -71,9 +71,6 @@ CLICON_PROMPT="%U@%H %W> ";
|
||||||
CLICON_PLUGIN="example_cli";
|
CLICON_PLUGIN="example_cli";
|
||||||
|
|
||||||
# Autocli syntax tree operations
|
# Autocli syntax tree operations
|
||||||
edit @datamodelshow, cli_auto_edit("basemodel");
|
|
||||||
up, cli_auto_up("basemodel");
|
|
||||||
top, cli_auto_top("basemodel");
|
|
||||||
set @datamodel, cli_auto_set();
|
set @datamodel, cli_auto_set();
|
||||||
merge @datamodel, cli_auto_merge();
|
merge @datamodel, cli_auto_merge();
|
||||||
create @datamodel, cli_auto_create();
|
create @datamodel, cli_auto_create();
|
||||||
|
|
@ -117,8 +117,6 @@ show {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto {
|
auto {
|
||||||
edit @datamodelshow, cli_auto_edit("basemodel");
|
|
||||||
top, cli_auto_top("basemodel");
|
|
||||||
set @datamodel, cli_auto_set();
|
set @datamodel, cli_auto_set();
|
||||||
show, cli_auto_show("datamodel", "candidate", "text", true, false);
|
show, cli_auto_show("datamodel", "candidate", "text", true, false);
|
||||||
}
|
}
|
||||||
|
|
@ -194,8 +192,7 @@ expectpart "$(echo "show $top config parameter ?" | $clixon_cli -f $cfg 2> /dev/
|
||||||
new "Show $top config parameter <name>"
|
new "Show $top config parameter <name>"
|
||||||
expectpart "$(echo "show $top config parameter a ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 value '<cr>' --not-- '<value>'
|
expectpart "$(echo "show $top config parameter a ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 value '<cr>' --not-- '<value>'
|
||||||
|
|
||||||
# Have not succeeded with this, and I am not sure it is necessary?
|
# Special mode, to do "show leaf", but not "show leaf <value>"
|
||||||
# Ie to do "show leaf", but not "show leaf <value>"
|
|
||||||
# <cr> is enabled but no value on leafs
|
# <cr> is enabled but no value on leafs
|
||||||
new "Show $top config parameter <name> value"
|
new "Show $top config parameter <name> value"
|
||||||
expectpart "$(echo "show $top config parameter a value ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 '<cr>' --not-- '<value>'
|
expectpart "$(echo "show $top config parameter a value ?" | $clixon_cli -f $cfg 2> /dev/null)" 0 '<cr>' --not-- '<value>'
|
||||||
Loading…
Add table
Add a link
Reference in a new issue