yanglint FEATURE do not load ietf-yang-library by default
To avoid validation errors caused by this module.
Fixes #1371
diff --git a/tools/lint/cmd_clear.c b/tools/lint/cmd_clear.c
index 5cece3a..13d910a 100644
--- a/tools/lint/cmd_clear.c
+++ b/tools/lint/cmd_clear.c
@@ -28,16 +28,17 @@
void
cmd_clear_help(void)
{
- printf("Usage: clear [<yang-library-data> | --external]\n"
+ printf("Usage: clear [--yang-library]\n"
" Replace the current context with an empty one, searchpaths\n"
" are not kept.\n"
+ " -y, --yang-library\n"
+ " Load and implement internal \"ietf-yang-library\" YANG module.\n"
+ " Note that this module includes definitions of mandatory state\n"
+ " data that can result in unexpected data validation errors.\n");
+#if 0
" If <yang-library-data> path specified, load the modules\n"
" according to the provided yang library data.\n"
- " -e, --external-yl\n"
- " When creating the new context, do not load the internal\n"
- " ietf-yang-library and let user to load ietf-yang-library from\n"
- " file. Note, that until a compatible ietf-yang-library loaded,\n"
- " the 'list' command does not work.\n");
+#endif
}
void
@@ -47,21 +48,21 @@
char **argv = NULL;
int opt, opt_index;
struct option options[] = {
- {"external-yl", no_argument, NULL, 'e'},
- {"help", no_argument, NULL, 'h'},
+ {"yang-library", no_argument, NULL, 'y'},
+ {"help", no_argument, NULL, 'h'},
{NULL, 0, NULL, 0}
};
- uint16_t options_ctx = 0;
+ uint16_t options_ctx = LY_CTX_NO_YANGLIBRARY;
struct ly_ctx *ctx_new;
if (parse_cmdline(cmdline, &argc, &argv)) {
goto cleanup;
}
- while ((opt = getopt_long(argc, argv, "eh", options, &opt_index)) != -1) {
+ while ((opt = getopt_long(argc, argv, "yh", options, &opt_index)) != -1) {
switch (opt) {
- case 'e':
- options_ctx |= LY_CTX_NO_YANGLIBRARY;
+ case 'y':
+ options_ctx &= ~LY_CTX_NO_YANGLIBRARY;
break;
case 'h':
cmd_clear_help();
@@ -72,12 +73,6 @@
}
}
- /* TODO ietf-yang-library support */
- if (argc != optind) {
- YLMSG_E("Creating context following the ietf-yang-library data is not yet supported.\n");
- goto cleanup;
- }
-
if (ly_ctx_new(NULL, options_ctx, &ctx_new)) {
YLMSG_W("Failed to create context.\n");
goto cleanup;
diff --git a/tools/lint/cmd_data.c b/tools/lint/cmd_data.c
index e2cd6fd..a78f06b 100644
--- a/tools/lint/cmd_data.c
+++ b/tools/lint/cmd_data.c
@@ -62,8 +62,9 @@
" -m, --merge Merge input data files into a single tree and validate at\n"
" once.The option has effect only for 'data' and 'config' TYPEs.\n"
" In case of using -x option, the data are always merged.\n"
- " -s, --strict Strict data parsing (do not skip unknown data), has no effect\n"
- " for schemas.\n"
+ " -n, --not-strict\n"
+ " Do not require strict data parsing (silently skip unknown data),\n"
+ " has no effect for schemas.\n\n"
" -O FILE, --operational=FILE\n"
" Provide optional data to extend validation of the 'rpc',\n"
" 'reply' or 'notif' TYPEs. The FILE is supposed to contain\n"
diff --git a/tools/lint/common.c b/tools/lint/common.c
index 796a450..968d00f 100644
--- a/tools/lint/common.c
+++ b/tools/lint/common.c
@@ -345,7 +345,7 @@
if (outformat != LYD_UNKNOWN) {
if (ly_ctx_get_yanglib_data(ctx, &ylib)) {
- YLMSG_E("Getting context info (ietf-yang-library data) failed.\n");
+ 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;
}
diff --git a/tools/lint/common.h b/tools/lint/common.h
index 21b8618..ce4793d 100644
--- a/tools/lint/common.h
+++ b/tools/lint/common.h
@@ -23,6 +23,11 @@
#define PROMPT "> "
/**
+ * @brief Default context creation options.
+ */
+#define YL_DEFAULT_CTX_OPTIONS LY_CTX_NO_YANGLIBRARY
+
+/**
* @brief log error message
*/
#define YLMSG_E(MSG, ...) \
diff --git a/tools/lint/main.c b/tools/lint/main.c
index 44eca9b..280df8c 100644
--- a/tools/lint/main.c
+++ b/tools/lint/main.c
@@ -49,7 +49,7 @@
linenoiseSetCompletionCallback(complete_cmd);
load_config();
- if (ly_ctx_new(NULL, 0, &ctx)) {
+ if (ly_ctx_new(NULL, YL_DEFAULT_CTX_OPTIONS, &ctx)) {
YLMSG_E("Failed to create context.\n");
return 1;
}
diff --git a/tools/lint/main_ni.c b/tools/lint/main_ni.c
index 1a17b7e..aa22c27 100644
--- a/tools/lint/main_ni.c
+++ b/tools/lint/main_ni.c
@@ -222,6 +222,11 @@
" -m, --merge Merge input data files into a single tree and validate at\n"
" once.The option has effect only for 'data' and 'config' TYPEs.\n\n"
+ " -y, --yang-library\n"
+ " Load and implement internal \"ietf-yang-library\" YANG module.\n"
+ " Note that this module includes definitions of mandatory state\n"
+ " data that can result in unexpected data validation errors.\n\n"
+
#if 0
" -y YANGLIB_PATH - Path to a yang-library data describing the initial context.\n\n"
"Tree output specific options:\n"
@@ -371,6 +376,7 @@
{"makeimplemented", no_argument, NULL, 'i'},
{"list", no_argument, NULL, 'l'},
{"merge", no_argument, NULL, 'm'},
+ {"yang-library", no_argument, NULL, 'y'},
{"output", required_argument, NULL, 'o'},
{"operational", required_argument, NULL, 'O'},
{"path", required_argument, NULL, 'p'},
@@ -383,13 +389,13 @@
{NULL, 0, NULL, 0}
};
- uint16_t options_ctx = 0;
+ uint16_t options_ctx = YL_DEFAULT_CTX_OPTIONS;
uint8_t data_type_set = 0;
#ifndef NDEBUG
- while ((opt = getopt_long(argc, argv, "d:Def:F:hilmo:p:P:qst:vV", options, &opt_index)) != -1) {
+ while ((opt = getopt_long(argc, argv, "d:Def:F:hilmyo:p:P:qst:vV", options, &opt_index)) != -1) {
#else
- while ((opt = getopt_long(argc, argv, "d:Def:F:G:hilmo:p:P:qst:vV", options, &opt_index)) != -1) {
+ while ((opt = getopt_long(argc, argv, "d:Def:F:G:hilmyo:p:P:qst:vV", options, &opt_index)) != -1) {
#endif
switch (opt) {
case 'd': /* --default */
@@ -556,6 +562,10 @@
c->data_merge = 1;
break;
+ case 'y': /* --yang-library */
+ options_ctx &= ~LY_CTX_NO_YANGLIBRARY;
+ break;
+
case 'h': /* --help */
help(0);
return 1;
diff --git a/tools/lint/tests/shunit2/list.sh b/tools/lint/tests/shunit2/list.sh
index dab04b7..d07b682 100755
--- a/tools/lint/tests/shunit2/list.sh
+++ b/tools/lint/tests/shunit2/list.sh
@@ -4,9 +4,7 @@
i ietf-yang-metadata@2016-08-05
I yang@2020-06-17
i ietf-inet-types@2013-07-15
- i ietf-yang-types@2013-07-15
- I ietf-datastores@2018-02-14
- I ietf-yang-library@2019-01-04"
+ i ietf-yang-types@2013-07-15"
testListEmptyContext() {
output=`${YANGLINT} -l`
@@ -18,9 +16,7 @@
I ietf-yang-metadata@2016-08-05
I yang@2020-06-17
I ietf-inet-types@2013-07-15
- I ietf-yang-types@2013-07-15
- I ietf-datastores@2018-02-14
- I ietf-yang-library@2019-01-04"
+ I ietf-yang-types@2013-07-15"
output=`${YANGLINT} -lii`
assertEquals "Unexpected list of modules in empty context with -ii." "${LIST_BASE_ALLIMPLEMENTED}" "${output}"
}