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 */
|
||||
switch (format){
|
||||
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;
|
||||
fprintf(stdout, "\n");
|
||||
break;
|
||||
|
|
@ -474,7 +474,7 @@ cli_auto_show(clicon_handle h,
|
|||
NETCONF_BASE_NAMESPACE, NETCONF_MESSAGE_ID_ATTR);
|
||||
if (pretty)
|
||||
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;
|
||||
fprintf(stdout, "</config></edit-config></rpc>]]>]]>\n");
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -127,6 +127,7 @@ xml2txt1(cxobj *xn,
|
|||
char *value;
|
||||
cg_var *cvi;
|
||||
cvec *cvk = NULL; /* vector of index keys */
|
||||
cbuf *cb = NULL;
|
||||
|
||||
if (xn == NULL || fn == NULL){
|
||||
clicon_err(OE_XML, EINVAL, "xn or fn is NULL");
|
||||
|
|
@ -171,15 +172,22 @@ xml2txt1(cxobj *xn,
|
|||
children++;
|
||||
if (children == 0){ /* If no children print line */
|
||||
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);
|
||||
if (*leafl) /* Skip keyword if leaflist */
|
||||
(*fn)(f, "%*s%s\n", 4*level, "", xml_value(xn));
|
||||
else if (index(value, ' ') != NULL) /* Add quotes if string contains spaces */
|
||||
(*fn)(f, "\"%s\";\n", xml_value(xn));
|
||||
if (index(value, ' ') != NULL)
|
||||
cprintf(cb, "\"%s\"", value);
|
||||
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;
|
||||
}
|
||||
case CX_ELMNT:
|
||||
(*fn)(f, "%*s%s", 4*level, "", xml_name(xn));
|
||||
cvi = NULL; /* Lists only */
|
||||
|
|
@ -227,28 +235,17 @@ xml2txt1(cxobj *xn,
|
|||
}
|
||||
}
|
||||
/* 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){
|
||||
*leafl = 0;
|
||||
(*fn)(f, "%*s\n", 4*(level+1), "]");
|
||||
}
|
||||
#endif
|
||||
if (!tleaf(xn))
|
||||
(*fn)(f, "%*s}\n", 4*level, "");
|
||||
ok:
|
||||
retval = 0;
|
||||
done:
|
||||
if (cb)
|
||||
cbuf_free(cb);
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -131,8 +131,6 @@ copy("Copy and create a new object"){
|
|||
}
|
||||
}
|
||||
discard("Discard edits (rollback 0)"), discard_changes();
|
||||
|
||||
|
||||
debug("Debugging parts of the system"){
|
||||
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"
|
||||
expectpart "$($clixon_cli -1 -f $cfg -l o set table parameter a array1 a)" 0 "^$"
|
||||
|
||||
new "cli create leaflist array1 b"
|
||||
expectpart "$($clixon_cli -1 -f $cfg -l o set table parameter a array1 b)" 0 "^$"
|
||||
new "cli create leaflist array1 b1 b2"
|
||||
expectpart "$($clixon_cli -1 -f $cfg -l o set table parameter a array1 \"b1 b2\")" 0 "^$"
|
||||
|
||||
new "cli create leaflist array2 c"
|
||||
expectpart "$($clixon_cli -1 -f $cfg -l o set table parameter a array2 c)" 0 "^$"
|
||||
new "cli create leaflist array2 c1 c2"
|
||||
expectpart "$($clixon_cli -1 -f $cfg -l o set table parameter a array2 \"c1 c2\")" 0 "^$"
|
||||
|
||||
new "cli commit"
|
||||
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"
|
||||
expectpart "$($clixon_cli -1 -f $cfg -l o delete all)" 0 "^$"
|
||||
|
||||
|
||||
new "cli load $format"
|
||||
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