yanglint REFACTOR parsing of --type argument
diff --git a/tools/lint/cmd_data.c b/tools/lint/cmd_data.c
index 4e5e935..26bedd5 100644
--- a/tools/lint/cmd_data.c
+++ b/tools/lint/cmd_data.c
@@ -254,28 +254,7 @@
                 return 1;
             }
 
-            if (!strcasecmp(optarg, "config")) {
-                yo->data_parse_options |= LYD_PARSE_NO_STATE;
-                yo->data_validate_options |= LYD_VALIDATE_NO_STATE;
-            } else if (!strcasecmp(optarg, "get")) {
-                yo->data_parse_options |= LYD_PARSE_ONLY;
-            } else if (!strcasecmp(optarg, "getconfig") || !strcasecmp(optarg, "get-config") || !strcasecmp(optarg, "edit")) {
-                yo->data_parse_options |= LYD_PARSE_ONLY | LYD_PARSE_NO_STATE;
-            } else if (!strcasecmp(optarg, "rpc") || !strcasecmp(optarg, "action")) {
-                yo->data_type = LYD_TYPE_RPC_YANG;
-            } else if (!strcasecmp(optarg, "nc-rpc")) {
-                yo->data_type = LYD_TYPE_RPC_NETCONF;
-            } else if (!strcasecmp(optarg, "reply") || !strcasecmp(optarg, "rpcreply")) {
-                yo->data_type = LYD_TYPE_REPLY_YANG;
-            } else if (!strcasecmp(optarg, "nc-reply")) {
-                yo->data_type = LYD_TYPE_REPLY_NETCONF;
-            } else if (!strcasecmp(optarg, "notif") || !strcasecmp(optarg, "notification")) {
-                yo->data_type = LYD_TYPE_NOTIF_YANG;
-            } else if (!strcasecmp(optarg, "nc-notif")) {
-                yo->data_type = LYD_TYPE_NOTIF_NETCONF;
-            } else if (!strcasecmp(optarg, "data")) {
-                /* default option */
-            } else {
+            if (yl_opt_update_data_type(optarg, yo)) {
                 YLMSG_E("Unknown data tree type %s.\n", optarg);
                 cmd_data_help_type();
                 return 1;
diff --git a/tools/lint/main_ni.c b/tools/lint/main_ni.c
index ea39c2e..35a0ff3 100644
--- a/tools/lint/main_ni.c
+++ b/tools/lint/main_ni.c
@@ -612,28 +612,7 @@
                 return -1;
             }
 
-            if (!strcasecmp(optarg, "config")) {
-                yo->data_parse_options |= LYD_PARSE_NO_STATE;
-                yo->data_validate_options |= LYD_VALIDATE_NO_STATE;
-            } else if (!strcasecmp(optarg, "get")) {
-                yo->data_parse_options |= LYD_PARSE_ONLY;
-            } else if (!strcasecmp(optarg, "getconfig") || !strcasecmp(optarg, "get-config") || !strcasecmp(optarg, "edit")) {
-                yo->data_parse_options |= LYD_PARSE_ONLY | LYD_PARSE_NO_STATE;
-            } else if (!strcasecmp(optarg, "rpc")) {
-                yo->data_type = LYD_TYPE_RPC_YANG;
-            } else if (!strcasecmp(optarg, "nc-rpc")) {
-                yo->data_type = LYD_TYPE_RPC_NETCONF;
-            } else if (!strcasecmp(optarg, "reply")) {
-                yo->data_type = LYD_TYPE_REPLY_YANG;
-            } else if (!strcasecmp(optarg, "nc-reply")) {
-                yo->data_type = LYD_TYPE_REPLY_NETCONF;
-            } else if (!strcasecmp(optarg, "notif")) {
-                yo->data_type = LYD_TYPE_NOTIF_YANG;
-            } else if (!strcasecmp(optarg, "nc-notif")) {
-                yo->data_type = LYD_TYPE_NOTIF_NETCONF;
-            } else if (!strcasecmp(optarg, "data")) {
-                /* default option */
-            } else {
+            if (yl_opt_update_data_type(optarg, yo)) {
                 YLMSG_E("Unknown data tree type %s\n", optarg);
                 help(1);
                 return -1;
diff --git a/tools/lint/yl_opt.c b/tools/lint/yl_opt.c
index 46887fc..e2aff06 100644
--- a/tools/lint/yl_opt.c
+++ b/tools/lint/yl_opt.c
@@ -169,6 +169,37 @@
     return 1;
 }
 
+int
+yl_opt_update_data_type(const char *arg, struct yl_opt *yo)
+{
+    if (!strcasecmp(arg, "config")) {
+        yo->data_parse_options |= LYD_PARSE_NO_STATE;
+        yo->data_validate_options |= LYD_VALIDATE_NO_STATE;
+    } else if (!strcasecmp(arg, "get")) {
+        yo->data_parse_options |= LYD_PARSE_ONLY;
+    } else if (!strcasecmp(arg, "getconfig") || !strcasecmp(arg, "get-config") || !strcasecmp(arg, "edit")) {
+        yo->data_parse_options |= LYD_PARSE_ONLY | LYD_PARSE_NO_STATE;
+    } else if (!strcasecmp(arg, "rpc") || !strcasecmp(arg, "action")) {
+        yo->data_type = LYD_TYPE_RPC_YANG;
+    } else if (!strcasecmp(arg, "nc-rpc")) {
+        yo->data_type = LYD_TYPE_RPC_NETCONF;
+    } else if (!strcasecmp(arg, "reply") || !strcasecmp(arg, "rpcreply")) {
+        yo->data_type = LYD_TYPE_REPLY_YANG;
+    } else if (!strcasecmp(arg, "nc-reply")) {
+        yo->data_type = LYD_TYPE_REPLY_NETCONF;
+    } else if (!strcasecmp(arg, "notif") || !strcasecmp(arg, "notification")) {
+        yo->data_type = LYD_TYPE_NOTIF_YANG;
+    } else if (!strcasecmp(arg, "nc-notif")) {
+        yo->data_type = LYD_TYPE_NOTIF_NETCONF;
+    } else if (!strcasecmp(arg, "data")) {
+        /* default option */
+    } else {
+        return 1;
+    }
+
+    return 0;
+}
+
 void
 free_cmdline(char *argv[])
 {
diff --git a/tools/lint/yl_opt.h b/tools/lint/yl_opt.h
index 8ce8ea6..4e3bdf0 100644
--- a/tools/lint/yl_opt.h
+++ b/tools/lint/yl_opt.h
@@ -179,6 +179,15 @@
 int yl_opt_update_out_format(const char *arg, struct yl_opt *yo);
 
 /**
+ * @brief Update @p yo according to the @p arg of the data --type parameter.
+ *
+ * @param[in] arg Format parameter argument (for example config, rpc, ...).
+ * @param[out] yo yanglint options used to update.
+ * @return 0 on success.
+ */
+int yl_opt_update_data_type(const char *arg, struct yl_opt *yo);
+
+/**
  * @brief Helper function to prepare argc, argv pair from a command line string.
  *
  * @param[in] cmdline Complete command line string.