From 01327fc8f0d8a75f0b4ce31695d77840e43d40a7 Mon Sep 17 00:00:00 2001 From: Olof hagsand Date: Sun, 18 Feb 2024 11:21:31 +0100 Subject: [PATCH] Added cli expand_yang() function --- apps/cli/cli_show.c | 31 +++++++++++++++++-------------- apps/cli/clixon_cli_api.h | 2 +- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/apps/cli/cli_show.c b/apps/cli/cli_show.c index 3e420344..951f0627 100644 --- a/apps/cli/cli_show.c +++ b/apps/cli/cli_show.c @@ -451,26 +451,29 @@ expand_dbvar(void *h, return retval; } -/*! Completion callback of variable for yang schema +/*! Completion callback of variable for yang schema list or container nodes * + * Typical yang: + * container foo { list bar; } + * augment foo fie; + * This function expands to bar, fie... * @param[in] h clicon handle - * @param[in] name Name of this function (eg "expand_dbvar") + * @param[in] name Name of this function * @param[in] cvv The command so far. Eg: cvec [0]:"a 5 b"; [1]: x=5; * @param[in] argv Arguments given at the callback: - * Absolute YANG schema-node - * * List of variable names in cvv for traversing yang + * Absolute YANG schema-node (eg: /ctrl:services) * @param[out] commands vector of function pointers to callback functions * @param[out] helptxt vector of pointers to helptexts * @retval 0 OK * @retval -1 Error */ int -expand_augment(void *h, - char *name, - cvec *cvv, - cvec *argv, - cvec *commands, - cvec *helptexts) +expand_yang(void *h, + char *name, + cvec *cvv, + cvec *argv, + cvec *commands, + cvec *helptexts) { int retval = -1; int argc = 0; @@ -481,12 +484,12 @@ expand_augment(void *h, yang_stmt *yn = NULL; yang_stmt *ydesc; - if (argv == NULL || cvec_len(argv) < 1){ - clixon_err(OE_PLUGIN, EINVAL, "requires arguments: *"); + if (argv == NULL || cvec_len(argv) != 1){ + clixon_err(OE_PLUGIN, EINVAL, "requires arguments: "); goto done; } if ((cv = cvec_i(argv, argc++)) == NULL){ - clixon_err(OE_PLUGIN, 0, "Error when accessing argument "); + clixon_err(OE_PLUGIN, 0, "Error when accessing argument "); goto done; } schema_nodeid = cv_string_get(cv); @@ -498,7 +501,7 @@ expand_augment(void *h, goto done; yn = NULL; while ((yn = yn_each(yres, yn)) != NULL) { - if (yang_keyword_get(yn) != Y_LIST) + if (yang_keyword_get(yn) != Y_LIST && yang_keyword_get(yn) != Y_CONTAINER) continue; cvec_add_string(commands, NULL, yang_argument_get(yn)); if ((ydesc = yang_find(yn, Y_DESCRIPTION, NULL)) != NULL) diff --git a/apps/cli/clixon_cli_api.h b/apps/cli/clixon_cli_api.h index 6753eaf0..8c50f9bd 100644 --- a/apps/cli/clixon_cli_api.h +++ b/apps/cli/clixon_cli_api.h @@ -119,7 +119,7 @@ int cli_process_control(clixon_handle h, cvec *vars, cvec *argv); /* In cli_show.c */ int expand_dbvar(void *h, char *name, cvec *cvv, cvec *argv, cvec *commands, cvec *helptexts); -int expand_augment(void *h, char *name, cvec *cvv, cvec *argv, +int expand_yang(void *h, char *name, cvec *cvv, cvec *argv, cvec *commands, cvec *helptexts); int clixon_cli2file(clixon_handle h, FILE *f, cxobj *xn, char *prepend, clicon_output_cb *fn, int skiptop); int clixon_cli2cbuf(clixon_handle h, cbuf *cb, cxobj *xn, char *prepend, int skiptop);