CLI configurable format: [Default format should be configurable](https://github.com/clicon/clixon-controller/issues/87)

Added option: `CLICON_CLI_OUTPUT_FORMAT` - Default CLI output format
This commit is contained in:
Olof hagsand 2024-04-05 15:13:24 +02:00
parent bd3a841103
commit 60a774cbf7
18 changed files with 168 additions and 83 deletions

View file

@ -926,6 +926,7 @@ cli_validate(clixon_handle h,
* @param[in] db2 Name of second datastrore
* @retval 0 OK
* @retval -1 Error
* @note JSON and CLI are NYI
*/
int
compare_db_names(clixon_handle h,
@ -975,7 +976,7 @@ compare_db_names(clixon_handle h,
goto done;
cligen_output(stdout, "%s", cbuf_get(cb));
break;
case FORMAT_JSON:
case FORMAT_JSON: /* XXX NYI */
case FORMAT_CLI:
if (clixon_compare_xmls(xc1, xc2, format) < 0) /* astext? */
goto done;
@ -1023,6 +1024,14 @@ compare_dbs(clixon_handle h,
clixon_err(OE_XML, 0, "format not found %s", formatstr);
goto done;
}
/* Special default format handling */
if (format == FORMAT_DEFAULT){
formatstr = clicon_option_str(h, "CLICON_CLI_OUTPUT_FORMAT");
if ((int)(format = format_str2int(formatstr)) < 0){
clixon_err(OE_PLUGIN, 0, "Not valid format: %s", formatstr);
goto done;
}
}
if (compare_db_names(h, format, db1, db2) < 0)
goto done;
retval = 0;
@ -1318,6 +1327,8 @@ save_config_file(clixon_handle h,
goto done;
fprintf(f, "</edit-config></rpc>]]>]]>\n");
break;
default:
break;
} /* switch */
retval = 0;
/* Fall through */