* Added PRETTYPRINT_INDENT compile-time option controlling indentation level for XML,JSON and TEXT
* Default value is `3`
This commit is contained in:
parent
1830381249
commit
56f4bb45cc
11 changed files with 73 additions and 1152 deletions
|
|
@ -57,6 +57,8 @@ Expected: End of 2022
|
|||
|
||||
Users may have to change how they access the system
|
||||
|
||||
* Added `PRETTYPRINT_INDENT` compile-time option controlling indentation level for XML,JSON and TEXT
|
||||
* Default value is `3`
|
||||
* NETCONF: Removed `message-id` from hello protocol following RFC 6241
|
||||
* See [message-id present on netconf app "hello"](https://github.com/clicon/clixon/issues/369)
|
||||
|
||||
|
|
@ -64,6 +66,8 @@ Users may have to change how they access the system
|
|||
|
||||
Developers may need to change their code
|
||||
|
||||
* [Code formatting: Change indentation style to space](https://github.com/clicon/clixon/issues/379)
|
||||
* Applies to all c/h/y/l/sh files and .editorconfig
|
||||
* C API changes
|
||||
* Added `defaults` parameter to `clicon_rpc_get_pageable_list()`
|
||||
* `clicon_rpc_commit()` and `cli_commit`
|
||||
|
|
@ -75,8 +79,6 @@ Developers may need to change their code
|
|||
|
||||
### Minor features
|
||||
|
||||
* [Code formatting: Change indentation style to space](https://github.com/clicon/clixon/issues/379)
|
||||
* Applies to all c/h/y/l/sh files and .editorconfig
|
||||
* Added warning if modstate is not present in datastore if `CLICON_XMLDB_MODSTATE` is set.
|
||||
|
||||
### Corrected Bugs
|
||||
|
|
|
|||
|
|
@ -411,7 +411,7 @@ show_yang(clicon_handle h,
|
|||
* @param[in] state
|
||||
* @param[in] withdefault RFC 6243 with-default modes
|
||||
* @param[in] extdefault with-defaults with propriatary extensions
|
||||
* @param[in] prefix CLI prefix to prepend cli syntax, eg "set "
|
||||
* @param[in] prepend CLI prefix to prepend cli syntax, eg "set "
|
||||
* @param[in] xpath XPath
|
||||
* @param[in] nsc Namespace mapping for xpath
|
||||
* @param[in] skiptop If set, do not show object itself, only its children
|
||||
|
|
@ -424,7 +424,7 @@ cli_show_common(clicon_handle h,
|
|||
int state,
|
||||
char *withdefault,
|
||||
char *extdefault,
|
||||
char *prefix,
|
||||
char *prepend,
|
||||
char *xpath,
|
||||
cvec *nsc,
|
||||
int skiptop
|
||||
|
|
@ -496,7 +496,7 @@ cli_show_common(clicon_handle h,
|
|||
goto done;
|
||||
break;
|
||||
case FORMAT_CLI:
|
||||
if (clixon_cli2file(h, stdout, xp, prefix, cligen_output, skiptop) < 0) /* cli syntax */
|
||||
if (clixon_cli2file(h, stdout, xp, prepend, cligen_output, skiptop) < 0) /* cli syntax */
|
||||
goto done;
|
||||
break;
|
||||
case FORMAT_NETCONF:
|
||||
|
|
@ -648,7 +648,7 @@ cli_show_option_withdefault(cvec *argv,
|
|||
* <state> true|false: also print state
|
||||
* <default> Retrieval mode: report-all, trim, explicit, report-all-tagged,
|
||||
* NULL, report-all-tagged-default, report-all-tagged-strip (extended)
|
||||
* <prefix> CLI prefix: prepend before cli syntax output
|
||||
* <prepend> CLI prefix: prepend before cli syntax output
|
||||
* @code
|
||||
* clispec:
|
||||
* show config, cli_show_config("running","xml");
|
||||
|
|
@ -675,7 +675,7 @@ cli_show_config(clicon_handle h,
|
|||
enum format_enum format = FORMAT_XML;
|
||||
cvec *nsc = NULL;
|
||||
int pretty = 1;
|
||||
char *prefix = NULL;
|
||||
char *prepend = NULL;
|
||||
int state = 0;
|
||||
char *withdefault = NULL; /* RFC 6243 modes */
|
||||
char *extdefault = NULL; /* with extended tagged modes */
|
||||
|
|
@ -684,7 +684,7 @@ cli_show_config(clicon_handle h,
|
|||
char *namespace = NULL;
|
||||
|
||||
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> <prefix>]", cvec_len(argv));
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected: <dbname> [<format><xpath> <namespace> <pretty> <state> <default> <prepend>]", cvec_len(argv));
|
||||
goto done;
|
||||
}
|
||||
dbname = cv_string_get(cvec_i(argv, argc++));
|
||||
|
|
@ -715,11 +715,11 @@ cli_show_config(clicon_handle h,
|
|||
goto done;
|
||||
}
|
||||
if (cvec_len(argv) > argc){
|
||||
prefix = cv_string_get(cvec_i(argv, argc++));
|
||||
prepend = cv_string_get(cvec_i(argv, argc++));
|
||||
}
|
||||
if (cli_show_common(h, dbname, format, pretty, state,
|
||||
withdefault, extdefault,
|
||||
prefix, xpath, nsc, 0) < 0)
|
||||
prepend, xpath, nsc, 0) < 0)
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -811,7 +811,7 @@ int cli_show_version(clicon_handle h,
|
|||
* @param[in] h Clixon handle
|
||||
* @param[in] cvv Vector of variables from CLIgen command-line
|
||||
* @param[in] argv String vector of show options, format:
|
||||
* <api_path_fmt> Generated API PATH
|
||||
* <api_path_fmt> Generated API PATH (this is added implicitly, not actually given in the cvv)
|
||||
* <dbname> Name of datastore, such as "running"
|
||||
* -- from here optional:
|
||||
* <format> "text"|"xml"|"json"|"cli"|"netconf" (see format_enum), default: xml
|
||||
|
|
@ -819,7 +819,7 @@ int cli_show_version(clicon_handle h,
|
|||
* <state> true|false: also print state
|
||||
* <default> Retrieval mode: report-all, trim, explicit, report-all-tagged,
|
||||
* NULL, report-all-tagged-default, report-all-tagged-strip (extended)
|
||||
* <prefix> CLI prefix: prepend before cli syntax output
|
||||
* <prepend> CLI prefix: prepend before cli syntax output
|
||||
* @code
|
||||
* clispec:
|
||||
* show config @datamodelshow, cli_show_auto("candidate", "xml");
|
||||
|
|
@ -846,7 +846,7 @@ cli_show_auto(clicon_handle h,
|
|||
enum format_enum format = FORMAT_XML;
|
||||
cvec *nsc = NULL;
|
||||
int pretty = 1;
|
||||
char *prefix = NULL;
|
||||
char *prepend = NULL;
|
||||
int state = 0;
|
||||
char *withdefault = NULL; /* RFC 6243 modes */
|
||||
char *extdefault = NULL; /* with extended tagged modes */
|
||||
|
|
@ -858,7 +858,7 @@ cli_show_auto(clicon_handle h,
|
|||
char *api_path_fmt; /* xml key format */
|
||||
|
||||
if (cvec_len(argv) < 2 || cvec_len(argv) > 7){
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected:: <api-path-fmt>* <database> [<format> <pretty> <state> <default> <cli-prefix>]", cvec_len(argv));
|
||||
clicon_err(OE_PLUGIN, EINVAL, "Received %d arguments. Expected:: <api-path-fmt>* <database> [<format> <pretty> <state> <default> <prepend>]", cvec_len(argv));
|
||||
goto done;
|
||||
}
|
||||
api_path_fmt = cv_string_get(cvec_i(argv, argc++));
|
||||
|
|
@ -881,7 +881,7 @@ cli_show_auto(clicon_handle h,
|
|||
goto done;
|
||||
}
|
||||
if (cvec_len(argv) > argc){
|
||||
prefix = cv_string_get(cvec_i(argv, argc++));
|
||||
prepend = cv_string_get(cvec_i(argv, argc++));
|
||||
}
|
||||
if ((yspec = clicon_dbspec_yang(h)) == NULL){
|
||||
clicon_err(OE_FATAL, 0, "No DB_SPEC");
|
||||
|
|
@ -897,7 +897,7 @@ cli_show_auto(clicon_handle h,
|
|||
}
|
||||
if (cli_show_common(h, dbname, format, pretty, state,
|
||||
withdefault, extdefault,
|
||||
prefix, xpath, nsc, 0) < 0)
|
||||
prepend, xpath, nsc, 0) < 0)
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -925,7 +925,7 @@ cli_show_auto(clicon_handle h,
|
|||
* <state> true|false: also print state
|
||||
* <default> Retrieval mode: report-all, trim, explicit, report-all-tagged,
|
||||
* NULL, report-all-tagged-default, report-all-tagged-strip (extended)
|
||||
* <prefix> CLI prefix: prepend before cli syntax output
|
||||
* <prepend> CLI prefix: prepend before cli syntax output
|
||||
* @code
|
||||
* clispec:
|
||||
* show config, cli_show_auto_mode("candidate");
|
||||
|
|
@ -953,7 +953,7 @@ cli_show_auto_mode(clicon_handle h,
|
|||
enum format_enum format = FORMAT_XML;
|
||||
cvec *nsc = NULL;
|
||||
int pretty = 1;
|
||||
char *prefix = NULL;
|
||||
char *prepend = NULL;
|
||||
int state = 0;
|
||||
char *withdefault = NULL; /* RFC 6243 modes */
|
||||
char *extdefault = NULL; /* with extended tagged modes */
|
||||
|
|
@ -986,7 +986,7 @@ cli_show_auto_mode(clicon_handle h,
|
|||
goto done;
|
||||
}
|
||||
if (cvec_len(argv) > argc){
|
||||
prefix = cv_string_get(cvec_i(argv, argc++));
|
||||
prepend = cv_string_get(cvec_i(argv, argc++));
|
||||
}
|
||||
/* Store this as edit-mode */
|
||||
if (clicon_data_get(h, "cli-edit-mode", &api_path) == 0 && strlen(api_path))
|
||||
|
|
@ -1006,7 +1006,7 @@ cli_show_auto_mode(clicon_handle h,
|
|||
skiptop = (strcmp(xpath,"/") != 0);
|
||||
if (cli_show_common(h, dbname, format, pretty, state,
|
||||
withdefault, extdefault,
|
||||
prefix, xpath, nsc, skiptop) < 0)
|
||||
prepend, xpath, nsc, skiptop) < 0)
|
||||
goto done;
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -1017,6 +1017,7 @@ cli_show_auto_mode(clicon_handle h,
|
|||
return retval;
|
||||
}
|
||||
|
||||
#if 1 // OBSOLETE
|
||||
/*! Obsolete Show configuration callback for autocli edit modes using tree working point
|
||||
*
|
||||
* @note Please use cli_show_auto_mode instead,
|
||||
|
|
@ -1050,6 +1051,7 @@ cli_auto_show(clicon_handle h,
|
|||
cvec_free(argv1);
|
||||
return retval;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*! Show clixon configuration options as loaded
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -179,3 +179,8 @@
|
|||
* // Here "s" is still open and you can reply on the non-ssl underlying socket
|
||||
*/
|
||||
#define HTTP_ON_HTTPS_REPLY
|
||||
|
||||
/*! Indentation number of spaces for XML, JSON and TEXT pretty-printed output.
|
||||
* Consider moving to configure.ac(compile-time) or to clixon-config.yang(run-time)
|
||||
*/
|
||||
#define PRETTYPRINT_INDENT 3
|
||||
|
|
|
|||
|
|
@ -77,8 +77,6 @@
|
|||
#include "clixon_json.h"
|
||||
#include "clixon_json_parse.h"
|
||||
|
||||
#define JSON_INDENT 2 /* maybe we should set this programmatically? */
|
||||
|
||||
/* Let xml2json_cbuf_vec() return json array: [a,b].
|
||||
ALternative is to create a pseudo-object and return that: {top:{a,b}}
|
||||
*/
|
||||
|
|
@ -731,11 +729,11 @@ json_metadata_encoding(cbuf *cb,
|
|||
cprintf(cb, "%s\":", name);
|
||||
if (list)
|
||||
cprintf(cb, "[");
|
||||
cprintf(cb, "%*s", pretty?((level+1)*JSON_INDENT):0, "{");
|
||||
cprintf(cb, "%*s", pretty?((level+1)*PRETTYPRINT_INDENT):0, "{");
|
||||
cprintf(cb, "\"%s:%s\":%s", modname2, name2, val);
|
||||
cprintf(cb, "%*s", pretty?((level+1)*JSON_INDENT):0, "}");
|
||||
cprintf(cb, "%*s", pretty?((level+1)*PRETTYPRINT_INDENT):0, "}");
|
||||
if (list)
|
||||
cprintf(cb, "%*s", pretty?(level*JSON_INDENT):0, "]");
|
||||
cprintf(cb, "%*s", pretty?(level*PRETTYPRINT_INDENT):0, "]");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -896,7 +894,7 @@ xml2json1_cbuf(cbuf *cb,
|
|||
break;
|
||||
case NO_ARRAY:
|
||||
if (!flat){
|
||||
cprintf(cb, "%*s\"", pretty?(level*JSON_INDENT):0, "");
|
||||
cprintf(cb, "%*s\"", pretty?(level*PRETTYPRINT_INDENT):0, "");
|
||||
if (modname)
|
||||
cprintf(cb, "%s:", modname);
|
||||
cprintf(cb, "%s\":%s", xml_name(x), pretty?" ":"");
|
||||
|
|
@ -917,14 +915,14 @@ xml2json1_cbuf(cbuf *cb,
|
|||
break;
|
||||
case FIRST_ARRAY:
|
||||
case SINGLE_ARRAY:
|
||||
cprintf(cb, "%*s\"", pretty?(level*JSON_INDENT):0, "");
|
||||
cprintf(cb, "%*s\"", pretty?(level*PRETTYPRINT_INDENT):0, "");
|
||||
if (modname)
|
||||
cprintf(cb, "%s:", modname);
|
||||
cprintf(cb, "%s\":%s", xml_name(x), pretty?" ":"");
|
||||
level++;
|
||||
cprintf(cb, "[%s%*s",
|
||||
pretty?"\n":"",
|
||||
pretty?(level*JSON_INDENT):0, "");
|
||||
pretty?(level*PRETTYPRINT_INDENT):0, "");
|
||||
switch (childt){
|
||||
case NULL_CHILD:
|
||||
if (nullchild(cb, x, ys) < 0)
|
||||
|
|
@ -943,7 +941,7 @@ xml2json1_cbuf(cbuf *cb,
|
|||
case LAST_ARRAY:
|
||||
level++;
|
||||
cprintf(cb, "%*s",
|
||||
pretty?(level*JSON_INDENT):0, "");
|
||||
pretty?(level*PRETTYPRINT_INDENT):0, "");
|
||||
switch (childt){
|
||||
case NULL_CHILD:
|
||||
if (nullchild(cb, x, ys) < 0)
|
||||
|
|
@ -1007,7 +1005,7 @@ xml2json1_cbuf(cbuf *cb,
|
|||
case ANY_CHILD:
|
||||
cprintf(cb, "%s%*s}",
|
||||
pretty?"\n":"",
|
||||
pretty?(level*JSON_INDENT):0, "");
|
||||
pretty?(level*PRETTYPRINT_INDENT):0, "");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
@ -1023,7 +1021,7 @@ xml2json1_cbuf(cbuf *cb,
|
|||
case ANY_CHILD:
|
||||
cprintf(cb, "%s%*s}",
|
||||
pretty?"\n":"",
|
||||
pretty?(level*JSON_INDENT):0, "");
|
||||
pretty?(level*PRETTYPRINT_INDENT):0, "");
|
||||
level--;
|
||||
break;
|
||||
default:
|
||||
|
|
@ -1040,7 +1038,7 @@ xml2json1_cbuf(cbuf *cb,
|
|||
case ANY_CHILD:
|
||||
cprintf(cb, "%s%*s}",
|
||||
pretty?"\n":"",
|
||||
pretty?(level*JSON_INDENT):0, "");
|
||||
pretty?(level*PRETTYPRINT_INDENT):0, "");
|
||||
cprintf(cb, "%s",pretty?"\n":"");
|
||||
level--;
|
||||
break;
|
||||
|
|
@ -1048,7 +1046,7 @@ xml2json1_cbuf(cbuf *cb,
|
|||
break;
|
||||
}
|
||||
cprintf(cb, "%*s]",
|
||||
pretty?(level*JSON_INDENT):0,"");
|
||||
pretty?(level*PRETTYPRINT_INDENT):0,"");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
@ -1095,7 +1093,7 @@ xml2json_cbuf1(cbuf *cb,
|
|||
goto ok;
|
||||
}
|
||||
cprintf(cb, "%*s{%s",
|
||||
pretty?level*JSON_INDENT:0,"",
|
||||
pretty?level*PRETTYPRINT_INDENT:0,"",
|
||||
pretty?"\n":"");
|
||||
|
||||
if (y != NULL){
|
||||
|
|
@ -1120,7 +1118,7 @@ xml2json_cbuf1(cbuf *cb,
|
|||
goto done;
|
||||
cprintf(cb, "%s%*s}%s",
|
||||
pretty?"\n":"",
|
||||
pretty?level*JSON_INDENT:0,"",
|
||||
pretty?level*PRETTYPRINT_INDENT:0,"",
|
||||
pretty?"\n":"");
|
||||
ok:
|
||||
retval = 0;
|
||||
|
|
@ -1239,11 +1237,7 @@ xml2json_cbuf_vec(cbuf *cb,
|
|||
if (xml2json1_cbuf(cb,
|
||||
xp,
|
||||
NO_ARRAY,
|
||||
#if 1
|
||||
level,
|
||||
#else
|
||||
level+1,
|
||||
#endif
|
||||
pretty,
|
||||
1, NULL, NULL) < 0)
|
||||
goto done;
|
||||
|
|
|
|||
|
|
@ -71,8 +71,11 @@
|
|||
/* Size of json read buffer when reading from file*/
|
||||
#define BUFLEN 1024
|
||||
|
||||
/* Name of xml top object created by parse functions */
|
||||
#define TOP_SYMBOL "top"
|
||||
/* Name of xml top object created by parse functions
|
||||
* See also DATASTORE_TOP_SYMBOL which is the clixon datastore top symbol. By default also config
|
||||
*/
|
||||
|
||||
#define TEXT_TOP_SYMBOL "top"
|
||||
|
||||
/*! x is element and has eactly one child which in turn has none
|
||||
* @see child_type in clixon_json.c
|
||||
|
|
@ -100,7 +103,7 @@ tleaf(cxobj *x)
|
|||
* @param[in] xn XML object to print
|
||||
* @param[in] fn Callback to make print function
|
||||
* @param[in] f File to print to
|
||||
* @param[in] level Print 4 spaces per level in front of each line
|
||||
* @param[in] level Print PRETTYPRINT_INDENT spaces per level in front of each line
|
||||
* @param[in] autocliext How to handle autocli extensions: 0: ignore 1: follow
|
||||
* @param[in,out] leafl Leaflist state for keeping track of when [] ends
|
||||
* @param[in,out] leaflname Leaflist state for []
|
||||
|
|
@ -171,7 +174,7 @@ xml2txt1(cxobj *xn,
|
|||
else{
|
||||
*leafl = 0;
|
||||
*leaflname = NULL;
|
||||
(*fn)(f, "%*s\n", 4*(level), "]");
|
||||
(*fn)(f, "%*s\n", PRETTYPRINT_INDENT*(level), "]");
|
||||
}
|
||||
}
|
||||
xc = NULL; /* count children (elements and bodies, not attributes) */
|
||||
|
|
@ -191,13 +194,13 @@ xml2txt1(cxobj *xn,
|
|||
else
|
||||
cprintf(cb, "%s", value);
|
||||
if (*leafl) /* Skip keyword if leaflist */
|
||||
(*fn)(f, "%*s%s\n", 4*level, "", cbuf_get(cb));
|
||||
(*fn)(f, "%*s%s\n", PRETTYPRINT_INDENT*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));
|
||||
(*fn)(f, "%*s%s", PRETTYPRINT_INDENT*level, "", xml_name(xn));
|
||||
cvi = NULL; /* Lists only */
|
||||
while ((cvi = cvec_each(cvk, cvi)) != NULL) {
|
||||
if ((xc = xml_find_type(xn, NULL, cv_string_get(cvi), CX_ELMNT)) != NULL)
|
||||
|
|
@ -211,7 +214,7 @@ xml2txt1(cxobj *xn,
|
|||
goto ok;
|
||||
}
|
||||
if (*leafl == 0){
|
||||
(*fn)(f, "%*s", 4*level, "");
|
||||
(*fn)(f, "%*s", PRETTYPRINT_INDENT*level, "");
|
||||
#ifndef TEXT_SYNTAX_NOPREFIX
|
||||
if (prefix)
|
||||
(*fn)(f, "%s:", prefix);
|
||||
|
|
@ -247,10 +250,10 @@ xml2txt1(cxobj *xn,
|
|||
/* Stop leaf-list printing (ie []) if no longer leaflist and same name */
|
||||
if (yn && yang_keyword_get(yn) != Y_LEAF_LIST && *leafl != 0){
|
||||
*leafl = 0;
|
||||
(*fn)(f, "%*s\n", 4*(level+1), "]");
|
||||
(*fn)(f, "%*s\n", PRETTYPRINT_INDENT*(level+1), "]");
|
||||
}
|
||||
if (!tleaf(xn))
|
||||
(*fn)(f, "%*s}\n", 4*level, "");
|
||||
(*fn)(f, "%*s}\n", PRETTYPRINT_INDENT*level, "");
|
||||
ok:
|
||||
retval = 0;
|
||||
done:
|
||||
|
|
@ -263,7 +266,7 @@ xml2txt1(cxobj *xn,
|
|||
*
|
||||
* @param[in] f File to print to
|
||||
* @param[in] xn XML object to print
|
||||
* @param[in] level Print 4 spaces per level in front of each line
|
||||
* @param[in] level Print PRETTYPRINT_INDENT spaces per level in front of each line
|
||||
* @param[in] fn File print function (if NULL, use fprintf)
|
||||
* @param[in] skiptop 0: Include top object 1: Skip top-object, only children,
|
||||
* @param[in] autocliext How to handle autocli extensions: 0: ignore 1: follow
|
||||
|
|
@ -563,7 +566,7 @@ clixon_text_syntax_parse_file(FILE *fp,
|
|||
textbuf[len++] = ch;
|
||||
if (ret == 0){
|
||||
if (*xt == NULL)
|
||||
if ((*xt = xml_new(TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
|
||||
if ((*xt = xml_new(TEXT_TOP_SYMBOL, NULL, CX_ELMNT)) == NULL)
|
||||
goto done;
|
||||
if (len){
|
||||
if ((ret = _text_syntax_parse(ptr, yb, yspec, *xt, xerr)) < 0)
|
||||
|
|
|
|||
|
|
@ -80,8 +80,6 @@
|
|||
*/
|
||||
/* Size of xml read buffer */
|
||||
#define BUFLEN 1024
|
||||
/* Indentation for xml pretty-print. Consider option? */
|
||||
#define XML_INDENT 3
|
||||
|
||||
/*------------------------------------------------------------------------
|
||||
* XML printing functions. Output a parse tree to file, string cligen buf
|
||||
|
|
@ -147,7 +145,7 @@ xml2file_recurse(FILE *f,
|
|||
(*fn)(f, "%s=\"%s\"", name, xml_value(x));
|
||||
break;
|
||||
case CX_ELMNT:
|
||||
(*fn)(f, "%*s<", pretty?(level*XML_INDENT):0, "");
|
||||
(*fn)(f, "%*s<", pretty?(level*PRETTYPRINT_INDENT):0, "");
|
||||
if (namespace)
|
||||
(*fn)(f, "%s:", namespace);
|
||||
(*fn)(f, "%s", name);
|
||||
|
|
@ -187,7 +185,7 @@ xml2file_recurse(FILE *f,
|
|||
goto done;
|
||||
}
|
||||
if (pretty && hasbody==0)
|
||||
(*fn)(f, "%*s", level*XML_INDENT, "");
|
||||
(*fn)(f, "%*s", level*PRETTYPRINT_INDENT, "");
|
||||
(*fn)(f, "</");
|
||||
if (namespace)
|
||||
(*fn)(f, "%s:", namespace);
|
||||
|
|
@ -249,7 +247,6 @@ clixon_xml2file(FILE *f,
|
|||
retval = 0;
|
||||
done:
|
||||
return retval;
|
||||
|
||||
}
|
||||
|
||||
/*! Print an XML tree structure to an output stream
|
||||
|
|
@ -356,7 +353,7 @@ clixon_xml2cbuf1(cbuf *cb,
|
|||
break;
|
||||
case CX_ELMNT:
|
||||
if (pretty)
|
||||
cprintf(cb, "%*s<", level*XML_INDENT, "");
|
||||
cprintf(cb, "%*s<", level*PRETTYPRINT_INDENT, "");
|
||||
else
|
||||
cbuf_append_str(cb, "<");
|
||||
if (namespace){
|
||||
|
|
@ -396,7 +393,7 @@ clixon_xml2cbuf1(cbuf *cb,
|
|||
if (clixon_xml2cbuf1(cb, xc, level+1, pretty, depth-1) < 0)
|
||||
goto done;
|
||||
if (pretty && hasbody == 0)
|
||||
cprintf(cb, "%*s", level*XML_INDENT, "");
|
||||
cprintf(cb, "%*s", level*PRETTYPRINT_INDENT, "");
|
||||
cbuf_append_str(cb, "</");
|
||||
if (namespace){
|
||||
cbuf_append_str(cb, namespace);
|
||||
|
|
@ -476,7 +473,7 @@ xmltree2cbuf(cbuf *cb,
|
|||
cxobj *xc;
|
||||
int i;
|
||||
|
||||
for (i=0; i<level*XML_INDENT; i++)
|
||||
for (i=0; i<level*PRETTYPRINT_INDENT; i++)
|
||||
cprintf(cb, " ");
|
||||
if (xml_type(x) != CX_BODY)
|
||||
cprintf(cb, "%s", xml_type2str(xml_type(x)));
|
||||
|
|
@ -495,7 +492,7 @@ xmltree2cbuf(cbuf *cb,
|
|||
while ((xc = xml_child_each(x, xc, -1)) != NULL)
|
||||
xmltree2cbuf(cb, xc, level+1);
|
||||
if (xml_child_nr(x)){
|
||||
for (i=0; i<level*XML_INDENT; i++)
|
||||
for (i=0; i<level*PRETTYPRINT_INDENT; i++)
|
||||
cprintf(cb, " ");
|
||||
cprintf(cb, "}\n");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
# Autocli show tests
|
||||
# Go through all formats and show for all formats
|
||||
# Formats: XML, JSON, TEXT, CLI, NETCONF
|
||||
# Pretty-print: false, true XXXX: align spaces
|
||||
# API: cli_show_auto_mode(), cli_show_auto(), cli_show_config() XXX
|
||||
# Pretty-print: false, true, indentation-level is 3 (see PRETTYPRINT_INDENT)
|
||||
# API: cli_show_auto_mode(), cli_show_auto(), cli_show_config()
|
||||
|
||||
# Magic line must be first in script (see README.md)
|
||||
s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||
|
|
@ -183,7 +183,7 @@ X='{"clixon-example:table":{"parameter":\[{"name":"x","value":"1","array1":\["a"
|
|||
expectpart "$($clixon_cli -1 -f $cfg -l o show config $format)" 0 "^$X$"
|
||||
|
||||
new "cli check show config $format pretty-print"
|
||||
expectpart "$($clixon_cli -1 -f $cfg -l o show config $format pretty-print)" 0 ' "clixon-example:table": {' --not-- ' "clixon-example:table": {'
|
||||
expectpart "$($clixon_cli -1 -f $cfg -l o show config $format pretty-print)" 0 ' "clixon-example:table": {' --not-- ' "clixon-example:table": {'
|
||||
|
||||
new "cli check show config $format non-auto"
|
||||
expectpart "$($clixon_cli -1 -f $cfg -l o show config $format config)" 0 "$X"
|
||||
|
|
@ -211,7 +211,7 @@ new "cli check show config $format"
|
|||
expectpart "$($clixon_cli -1 -f $cfg -l o show config $format)" 0 "clixon-example:table {" "parameter x {" "array1 \[" "parameter y {"
|
||||
|
||||
new "cli check show config $format pretty-print"
|
||||
expectpart "$($clixon_cli -1 -f $cfg -l o show config $format pretty-print)" 0 " parameter x {" --not-- " parameter x {"
|
||||
expectpart "$($clixon_cli -1 -f $cfg -l o show config $format pretty-print)" 0 " parameter x {" --not-- " parameter x {"
|
||||
|
||||
new "cli check show config $format non-auto"
|
||||
expectpart "$($clixon_cli -1 -f $cfg -l o show config $format config)" 0 "clixon-example:table {" "parameter x {" "array1 \[" "parameter y {"
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@ new "cli success validate"
|
|||
expectpart "$($clixon_cli -1 -f $cfg -l o validate)" 0 "^$"
|
||||
|
||||
new "cli compare diff"
|
||||
expectpart "$($clixon_cli -1 -f $cfg -l o show compare text)" 0 "+ address 1.2.3.4"
|
||||
expectpart "$($clixon_cli -1 -f $cfg -l o show compare text)" 0 "+ address 1.2.3.4"
|
||||
|
||||
new "cli start shell"
|
||||
expectpart "$($clixon_cli -1 -f $cfg -l o shell echo foo)" 0 "foo"
|
||||
|
|
|
|||
|
|
@ -133,8 +133,8 @@ ret=$($clixon_cli -1 -f $cfg show config)
|
|||
if [ $? -ne 0 ]; then
|
||||
err 0 $r
|
||||
fi
|
||||
if [ "$ret" != "clixon-hello:hello world;" ]; then
|
||||
err "clixon-hello:hello world;" "$ret"
|
||||
if [ "$ret" != "clixon-hello:hello world;" ]; then
|
||||
err "clixon-hello:hello world;" "$ret"
|
||||
fi
|
||||
|
||||
new "netconf edit-config"
|
||||
|
|
|
|||
|
|
@ -73,10 +73,10 @@ expecteofx "$clixon_util_json -j" 0 '{"a":[0,1,2,3]}' '{"a":"0"},{"a":"1"},{"a":
|
|||
JSON='{"json:c":{"a":42,"s":"string"}}'
|
||||
# Same with pretty-print
|
||||
JSONP='{
|
||||
"json:c": {
|
||||
"a": 42,
|
||||
"s": "string"
|
||||
}
|
||||
"json:c": {
|
||||
"a": 42,
|
||||
"s": "string"
|
||||
}
|
||||
}'
|
||||
|
||||
new "json no pp in/out"
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue