TEXT output/parser: fix space-separated leaf/leaf-lists
This commit is contained in:
parent
01b38c6645
commit
b1cb774c9d
3 changed files with 22 additions and 28 deletions
|
|
@ -452,7 +452,7 @@ cli_auto_show(clicon_handle h,
|
||||||
/* Print configuration according to format */
|
/* Print configuration according to format */
|
||||||
switch (format){
|
switch (format){
|
||||||
case FORMAT_XML:
|
case FORMAT_XML:
|
||||||
if (clixon_xml2file(stdout, xp, 0, pretty, fprintf, skiproot) < 0)
|
if (clixon_xml2file(stdout, xp, 0, pretty, cligen_output, skiproot) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
fprintf(stdout, "\n");
|
fprintf(stdout, "\n");
|
||||||
break;
|
break;
|
||||||
|
|
@ -474,7 +474,7 @@ cli_auto_show(clicon_handle h,
|
||||||
NETCONF_BASE_NAMESPACE, NETCONF_MESSAGE_ID_ATTR);
|
NETCONF_BASE_NAMESPACE, NETCONF_MESSAGE_ID_ATTR);
|
||||||
if (pretty)
|
if (pretty)
|
||||||
fprintf(stdout, "\n");
|
fprintf(stdout, "\n");
|
||||||
if (clixon_xml2file(stdout, xp, 2, pretty, fprintf, skiproot) < 0)
|
if (clixon_xml2file(stdout, xp, 2, pretty, cligen_output, skiproot) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
fprintf(stdout, "</config></edit-config></rpc>]]>]]>\n");
|
fprintf(stdout, "</config></edit-config></rpc>]]>]]>\n");
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,7 @@ xml2txt1(cxobj *xn,
|
||||||
char *value;
|
char *value;
|
||||||
cg_var *cvi;
|
cg_var *cvi;
|
||||||
cvec *cvk = NULL; /* vector of index keys */
|
cvec *cvk = NULL; /* vector of index keys */
|
||||||
|
cbuf *cb = NULL;
|
||||||
|
|
||||||
if (xn == NULL || fn == NULL){
|
if (xn == NULL || fn == NULL){
|
||||||
clicon_err(OE_XML, EINVAL, "xn or fn is NULL");
|
clicon_err(OE_XML, EINVAL, "xn or fn is NULL");
|
||||||
|
|
@ -171,15 +172,22 @@ xml2txt1(cxobj *xn,
|
||||||
children++;
|
children++;
|
||||||
if (children == 0){ /* If no children print line */
|
if (children == 0){ /* If no children print line */
|
||||||
switch (xml_type(xn)){
|
switch (xml_type(xn)){
|
||||||
case CX_BODY:
|
case CX_BODY:{
|
||||||
|
if ((cb = cbuf_new()) == NULL){
|
||||||
|
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
value = xml_value(xn);
|
value = xml_value(xn);
|
||||||
if (*leafl) /* Skip keyword if leaflist */
|
if (index(value, ' ') != NULL)
|
||||||
(*fn)(f, "%*s%s\n", 4*level, "", xml_value(xn));
|
cprintf(cb, "\"%s\"", value);
|
||||||
else if (index(value, ' ') != NULL) /* Add quotes if string contains spaces */
|
|
||||||
(*fn)(f, "\"%s\";\n", xml_value(xn));
|
|
||||||
else
|
else
|
||||||
(*fn)(f, "%s;\n", xml_value(xn));
|
cprintf(cb, "%s", value);
|
||||||
|
if (*leafl) /* Skip keyword if leaflist */
|
||||||
|
(*fn)(f, "%*s%s\n", 4*level, "", cbuf_get(cb));
|
||||||
|
else
|
||||||
|
(*fn)(f, "%s;\n", cbuf_get(cb));
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
case CX_ELMNT:
|
case CX_ELMNT:
|
||||||
(*fn)(f, "%*s%s", 4*level, "", xml_name(xn));
|
(*fn)(f, "%*s%s", 4*level, "", xml_name(xn));
|
||||||
cvi = NULL; /* Lists only */
|
cvi = NULL; /* Lists only */
|
||||||
|
|
@ -227,28 +235,17 @@ xml2txt1(cxobj *xn,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Stop leaf-list printing (ie []) if no longer leaflist and same name */
|
/* Stop leaf-list printing (ie []) if no longer leaflist and same name */
|
||||||
#if 0
|
|
||||||
if (*leafl != 0){
|
|
||||||
if (yn && yang_keyword_get(yn) == Y_LEAF_LIST &&
|
|
||||||
strcmp(*leaflname, yang_argument_get(yn))==0)
|
|
||||||
;
|
|
||||||
else{
|
|
||||||
*leafl = 0;
|
|
||||||
*leaflname = NULL;
|
|
||||||
(*fn)(f, "%*s\n", 4*(level+1), "]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (yn && yang_keyword_get(yn) != Y_LEAF_LIST && *leafl != 0){
|
if (yn && yang_keyword_get(yn) != Y_LEAF_LIST && *leafl != 0){
|
||||||
*leafl = 0;
|
*leafl = 0;
|
||||||
(*fn)(f, "%*s\n", 4*(level+1), "]");
|
(*fn)(f, "%*s\n", 4*(level+1), "]");
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
if (!tleaf(xn))
|
if (!tleaf(xn))
|
||||||
(*fn)(f, "%*s}\n", 4*level, "");
|
(*fn)(f, "%*s}\n", 4*level, "");
|
||||||
ok:
|
ok:
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
|
if (cb)
|
||||||
|
cbuf_free(cb);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -131,8 +131,6 @@ copy("Copy and create a new object"){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
discard("Discard edits (rollback 0)"), discard_changes();
|
discard("Discard edits (rollback 0)"), discard_changes();
|
||||||
|
|
||||||
|
|
||||||
debug("Debugging parts of the system"){
|
debug("Debugging parts of the system"){
|
||||||
cli("Set cli debug") <level:int32>("Set debug level (0..n)"), cli_debug_cli();
|
cli("Set cli debug") <level:int32>("Set debug level (0..n)"), cli_debug_cli();
|
||||||
}
|
}
|
||||||
|
|
@ -247,11 +245,11 @@ expectpart "$($clixon_cli -1 -f $cfg -l o shell echo foo)" 0 "foo"
|
||||||
new "cli create leaflist array1 a"
|
new "cli create leaflist array1 a"
|
||||||
expectpart "$($clixon_cli -1 -f $cfg -l o set table parameter a array1 a)" 0 "^$"
|
expectpart "$($clixon_cli -1 -f $cfg -l o set table parameter a array1 a)" 0 "^$"
|
||||||
|
|
||||||
new "cli create leaflist array1 b"
|
new "cli create leaflist array1 b1 b2"
|
||||||
expectpart "$($clixon_cli -1 -f $cfg -l o set table parameter a array1 b)" 0 "^$"
|
expectpart "$($clixon_cli -1 -f $cfg -l o set table parameter a array1 \"b1 b2\")" 0 "^$"
|
||||||
|
|
||||||
new "cli create leaflist array2 c"
|
new "cli create leaflist array2 c1 c2"
|
||||||
expectpart "$($clixon_cli -1 -f $cfg -l o set table parameter a array2 c)" 0 "^$"
|
expectpart "$($clixon_cli -1 -f $cfg -l o set table parameter a array2 \"c1 c2\")" 0 "^$"
|
||||||
|
|
||||||
new "cli commit"
|
new "cli commit"
|
||||||
expectpart "$($clixon_cli -1 -f $cfg -l o commit)" 0 "^$"
|
expectpart "$($clixon_cli -1 -f $cfg -l o commit)" 0 "^$"
|
||||||
|
|
@ -263,7 +261,6 @@ for format in cli text xml json; do
|
||||||
new "cli delete all"
|
new "cli delete all"
|
||||||
expectpart "$($clixon_cli -1 -f $cfg -l o delete all)" 0 "^$"
|
expectpart "$($clixon_cli -1 -f $cfg -l o delete all)" 0 "^$"
|
||||||
|
|
||||||
|
|
||||||
new "cli load $format"
|
new "cli load $format"
|
||||||
expectpart "$($clixon_cli -1 -f $cfg -l o load $dir/config.$format $format)" 0 "^$"
|
expectpart "$($clixon_cli -1 -f $cfg -l o load $dir/config.$format $format)" 0 "^$"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue