yanglint REFACTOR printing list in cmd_list
diff --git a/tools/lint/cmd_list.c b/tools/lint/cmd_list.c
index 47a7495..fb9a2a7 100644
--- a/tools/lint/cmd_list.c
+++ b/tools/lint/cmd_list.c
@@ -100,9 +100,86 @@
return 0;
}
+/**
+ * @brief Print yang library data.
+ *
+ * @param[in] ctx Context for libyang.
+ * @param[in] data_out_format Output format of printed data.
+ * @param[in] out Output handler.
+ * @return 0 on success.
+ */
+static int
+print_yang_lib_data(struct ly_ctx *ctx, LYD_FORMAT data_out_format, struct ly_out *out)
+{
+ struct lyd_node *ylib;
+
+ if (ly_ctx_get_yanglib_data(ctx, &ylib, "%u", ly_ctx_get_change_count(ctx))) {
+ YLMSG_E("Getting context info (ietf-yang-library data) failed. If the YANG module is missing or not implemented, use an option to add it internally.\n");
+ return 1;
+ }
+
+ lyd_print_all(out, ylib, data_out_format, 0);
+ lyd_free_all(ylib);
+
+ return 0;
+}
+
int
cmd_list_exec(struct ly_ctx **ctx, struct yl_opt *yo, const char *posv)
{
(void) posv;
- return print_list(yo->out, *ctx, yo->data_out_format);
+ uint32_t idx = 0, has_modules = 0;
+ const struct lys_module *mod;
+
+ if (yo->data_out_format != LYD_UNKNOWN) {
+ /* ietf-yang-library data are printed in the specified format */
+ if (print_yang_lib_data(*ctx, yo->data_out_format, yo->out)) {
+ return 1;
+ }
+ return 0;
+ }
+
+ /* iterate schemas in context and provide just the basic info */
+ ly_print(yo->out, "List of the loaded models:\n");
+ while ((mod = ly_ctx_get_module_iter(*ctx, &idx))) {
+ has_modules++;
+
+ /* conformance print */
+ if (mod->implemented) {
+ ly_print(yo->out, " I");
+ } else {
+ ly_print(yo->out, " i");
+ }
+
+ /* module print */
+ ly_print(yo->out, " %s", mod->name);
+ if (mod->revision) {
+ ly_print(yo->out, "@%s", mod->revision);
+ }
+
+ /* submodules print */
+ if (mod->parsed && mod->parsed->includes) {
+ uint64_t u = 0;
+
+ ly_print(yo->out, " (");
+ LY_ARRAY_FOR(mod->parsed->includes, u) {
+ ly_print(yo->out, "%s%s", !u ? "" : ",", mod->parsed->includes[u].name);
+ if (mod->parsed->includes[u].rev[0]) {
+ ly_print(yo->out, "@%s", mod->parsed->includes[u].rev);
+ }
+ }
+ ly_print(yo->out, ")");
+ }
+
+ /* finish the line */
+ ly_print(yo->out, "\n");
+ }
+
+ if (!has_modules) {
+ ly_print(yo->out, "\t(none)\n");
+ }
+
+ ly_print_flush(yo->out);
+
+ return 0;
}
diff --git a/tools/lint/common.c b/tools/lint/common.c
index 12b3733..88bd220 100644
--- a/tools/lint/common.c
+++ b/tools/lint/common.c
@@ -403,68 +403,6 @@
}
int
-print_list(struct ly_out *out, struct ly_ctx *ctx, LYD_FORMAT outformat)
-{
- struct lyd_node *ylib;
- uint32_t idx = 0, has_modules = 0;
- const struct lys_module *mod;
-
- if (outformat != LYD_UNKNOWN) {
- if (ly_ctx_get_yanglib_data(ctx, &ylib, "%u", ly_ctx_get_change_count(ctx))) {
- YLMSG_E("Getting context info (ietf-yang-library data) failed. If the YANG module is missing or not implemented, use an option to add it internally.\n");
- return 1;
- }
-
- lyd_print_all(out, ylib, outformat, 0);
- lyd_free_all(ylib);
- return 0;
- }
-
- /* iterate schemas in context and provide just the basic info */
- ly_print(out, "List of the loaded models:\n");
- while ((mod = ly_ctx_get_module_iter(ctx, &idx))) {
- has_modules++;
-
- /* conformance print */
- if (mod->implemented) {
- ly_print(out, " I");
- } else {
- ly_print(out, " i");
- }
-
- /* module print */
- ly_print(out, " %s", mod->name);
- if (mod->revision) {
- ly_print(out, "@%s", mod->revision);
- }
-
- /* submodules print */
- if (mod->parsed && mod->parsed->includes) {
- uint64_t u = 0;
-
- ly_print(out, " (");
- LY_ARRAY_FOR(mod->parsed->includes, u) {
- ly_print(out, "%s%s", !u ? "" : ",", mod->parsed->includes[u].name);
- if (mod->parsed->includes[u].rev[0]) {
- ly_print(out, "@%s", mod->parsed->includes[u].rev);
- }
- }
- ly_print(out, ")");
- }
-
- /* finish the line */
- ly_print(out, "\n");
- }
-
- if (!has_modules) {
- ly_print(out, "\t(none)\n");
- }
-
- ly_print_flush(out);
- return 0;
-}
-
-int
evaluate_xpath(const struct lyd_node *tree, const char *xpath)
{
struct ly_set *set = NULL;
diff --git a/tools/lint/common.h b/tools/lint/common.h
index 2a3bb50..c3d41aa 100644
--- a/tools/lint/common.h
+++ b/tools/lint/common.h
@@ -193,18 +193,6 @@
int get_format(const char *filepath, LYS_INFORMAT *schema_form, LYD_FORMAT *data_form);
/**
- * @brief Print list of schemas in the context.
- *
- * @param[in] out Output handler where to print.
- * @param[in] ctx Context to print.
- * @param[in] outformat Optional output format. If not specified (:LYD_UNKNOWN), a simple list with single module per line
- * is printed. Otherwise, the ietf-yang-library data are printed in the specified format.
- * @return zero in case the data successfully printed.
- * @return nonzero in case of error.
- */
-int print_list(struct ly_out *out, struct ly_ctx *ctx, LYD_FORMAT outformat);
-
-/**
* @brief Process the input data files - parse, validate and print according to provided options.
*
* @param[in] ctx libyang context with schema.
diff --git a/tools/lint/main_ni.c b/tools/lint/main_ni.c
index 41f595d..d89990c 100644
--- a/tools/lint/main_ni.c
+++ b/tools/lint/main_ni.c
@@ -775,7 +775,7 @@
if (yo.list) {
/* print the list of schemas */
- ret = print_list(yo.out, ctx, yo.data_out_format);
+ ret = cmd_list_exec(&ctx, &yo, NULL);
goto cleanup;
} else {
if (yo.feature_param_format) {