From 9b99d6341127885a2a60c32b0f2d57ad4283f3c5 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Thu, 13 Jan 2022 14:47:25 +0100 Subject: [PATCH] - fix autocli modes error of empty type - rename tests test_cli_auto -> test_autocli --- apps/cli/cli_auto.c | 2 +- apps/cli/cli_generate.c | 69 ++++++++++--------- ...{test_cli_auto.sh => test_autocli_edit.sh} | 9 +++ ...extension.sh => test_autocli_extension.sh} | 0 ...el.sh => test_autocli_listkey_compress.sh} | 3 - ..._cli_auto_spec.sh => test_autocli_spec.sh} | 3 - ...st_cli_auto_sub.sh => test_autocli_sub.sh} | 0 ...uto_treeref.sh => test_autocli_treeref.sh} | 5 +- 8 files changed, 48 insertions(+), 43 deletions(-) rename test/{test_cli_auto.sh => test_autocli_edit.sh} (97%) rename test/{test_cli_auto_extension.sh => test_autocli_extension.sh} (100%) rename test/{test_cli_auto_genmodel.sh => test_autocli_listkey_compress.sh} (99%) rename test/{test_cli_auto_spec.sh => test_autocli_spec.sh} (98%) rename test/{test_cli_auto_sub.sh => test_autocli_sub.sh} (100%) rename test/{test_cli_auto_treeref.sh => test_autocli_treeref.sh} (96%) diff --git a/apps/cli/cli_auto.c b/apps/cli/cli_auto.c index 56a6c8a7..623d29d8 100644 --- a/apps/cli/cli_auto.c +++ b/apps/cli/cli_auto.c @@ -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: * Generated API PATH (This is where we are in the tree) * Name of generated cligen parse-tree, eg "datamodel" diff --git a/apps/cli/cli_generate.c b/apps/cli/cli_generate.c index fc065104..c03f126c 100644 --- a/apps/cli/cli_generate.c +++ b/apps/cli/cli_generate.c @@ -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) @@ -757,14 +756,14 @@ yang2cli_leaf(clicon_handle h, int key_leaf, cbuf *cb) { - yang_stmt *yd; /* description */ - int retval = -1; - char *helptext = NULL; - char *s; - - int extralevel = 0; + yang_stmt *yd; /* description */ + int retval = -1; + char *helptext = NULL; + char *s; 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: