- 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
|
||||
* @param[in] h CLICON handle
|
||||
* @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:
|
||||
* <api_path_fmt> Generated API PATH (This is where we are in the tree)
|
||||
* <treename> Name of generated cligen parse-tree, eg "datamodel"
|
||||
|
|
|
|||
|
|
@ -135,11 +135,11 @@ cli_expand_var_generate(clicon_handle h,
|
|||
{
|
||||
int retval = -1;
|
||||
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;
|
||||
if (exist) {
|
||||
if (hideext) {
|
||||
retval = 1;
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -669,7 +669,6 @@ yang2cli_var(clicon_handle h,
|
|||
&options, &cvv, patterns, NULL, &fraction_digits) < 0)
|
||||
goto done;
|
||||
restype = yang_argument_get(yrestype);
|
||||
|
||||
if (strcmp(restype, "empty") == 0)
|
||||
goto ok;
|
||||
if (clicon_type2cv(origtype, restype, yreferred, &cvtype) < 0)
|
||||
|
|
@ -761,10 +760,10 @@ yang2cli_leaf(clicon_handle h,
|
|||
int retval = -1;
|
||||
char *helptext = NULL;
|
||||
char *s;
|
||||
|
||||
int extralevel = 0;
|
||||
autocli_listkw_t listkw;
|
||||
int exist = 0;
|
||||
int hideext = 0;
|
||||
int extralevel = 0;
|
||||
yang_stmt *yrestype; /* resolved type */
|
||||
|
||||
/* description */
|
||||
if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){
|
||||
|
|
@ -776,6 +775,13 @@ yang2cli_leaf(clicon_handle h,
|
|||
*s = '\0';
|
||||
}
|
||||
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)
|
||||
goto done;
|
||||
if (listkw == AUTOCLI_LISTKW_ALL ||
|
||||
|
|
@ -783,16 +789,30 @@ yang2cli_leaf(clicon_handle h,
|
|||
cprintf(cb, "%s", yang_argument_get(ys));
|
||||
yang2cli_helptext(cb, helptext);
|
||||
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;
|
||||
if (exist){
|
||||
cprintf(cb, ", hide{");
|
||||
extralevel = 1;
|
||||
if (hideext)
|
||||
cprintf(cb, ", hide"); /* XXX ensure always { */
|
||||
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)
|
||||
goto done;
|
||||
}
|
||||
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)
|
||||
goto done;
|
||||
}
|
||||
|
|
@ -828,7 +848,6 @@ yang2cli_container(clicon_handle h,
|
|||
char *helptext = NULL;
|
||||
char *s;
|
||||
int compress = 0;
|
||||
int hide_oc = 0;
|
||||
yang_stmt *ymod = NULL;
|
||||
int exist = 0;
|
||||
|
||||
|
|
@ -840,7 +859,7 @@ yang2cli_container(clicon_handle h,
|
|||
*/
|
||||
if (autocli_compress(h, ys, &compress) < 0)
|
||||
goto done;
|
||||
if (!compress && hide_oc == 0){
|
||||
if (!compress){
|
||||
cprintf(cb, "%*s%s", level*3, "", yang_argument_get(ys));
|
||||
if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != 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)
|
||||
if (yang2cli_stmt(h, yc, level+1, cb) < 0)
|
||||
goto done;
|
||||
if (!compress && hide_oc == 0)
|
||||
if (!compress)
|
||||
cprintf(cb, "%*s}\n", level*3, "");
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -1097,7 +1116,6 @@ cvec_add_name(cvec *cvv,
|
|||
|
||||
/*! 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:
|
||||
* 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)
|
||||
|
|
@ -1125,7 +1143,6 @@ cvec_add_name(cvec *cvv,
|
|||
* for y in modules
|
||||
* for co in top-level commands
|
||||
* 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
|
||||
yang2cli_post(clicon_handle h,
|
||||
|
|
@ -1187,18 +1204,6 @@ yang2cli_post(clicon_handle h,
|
|||
switch (yang_keyword_get(yc)){
|
||||
case Y_LEAF:
|
||||
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 ? */
|
||||
if (!yciskey)
|
||||
for (j = 0; j<pt_len_get(co_pt_get(co)); j++){
|
||||
|
|
|
|||
|
|
@ -145,6 +145,15 @@ EOF
|
|||
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>"
|
||||
|
||||
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
|
||||
edit table
|
||||
edit parameter a
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
#!/usr/bin/env bash
|
||||
# Tests for using the auto cli.
|
||||
# In particular setting a config, displaying as cli commands and reconfigure it
|
||||
|
|
@ -25,8 +24,6 @@ else
|
|||
mkdir $clidir
|
||||
fi
|
||||
|
||||
# Use yang in example
|
||||
|
||||
if [ ! -d "$OPENCONFIG" ]; then
|
||||
# err "Hmm Openconfig dir does not seem to exist, try git clone https://github.com/openconfig/public?"
|
||||
echo "...skipped: OPENCONFIG not set"
|
||||
|
|
@ -71,9 +71,6 @@ CLICON_PROMPT="%U@%H %W> ";
|
|||
CLICON_PLUGIN="example_cli";
|
||||
|
||||
# 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();
|
||||
merge @datamodel, cli_auto_merge();
|
||||
create @datamodel, cli_auto_create();
|
||||
|
|
@ -117,8 +117,6 @@ show {
|
|||
}
|
||||
|
||||
auto {
|
||||
edit @datamodelshow, cli_auto_edit("basemodel");
|
||||
top, cli_auto_top("basemodel");
|
||||
set @datamodel, cli_auto_set();
|
||||
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>"
|
||||
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?
|
||||
# Ie to do "show leaf", but not "show leaf <value>"
|
||||
# Special mode, to do "show leaf", but not "show leaf <value>"
|
||||
# <cr> is enabled but no value on leafs
|
||||
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>'
|
||||
Loading…
Add table
Add a link
Reference in a new issue