Browse Source

Add 'default' extension

Serj Kalichev 1 year ago
parent
commit
8d03a08685
7 changed files with 29 additions and 14 deletions
  1. 2 1
      bin/Makefile.am
  2. 3 5
      configure.ac
  3. 3 3
      src/Makefile.am
  4. 2 4
      src/pline.c
  5. 2 0
      src/private.h
  6. 11 1
      src/show.c
  7. 6 0
      yang/klish.yang

+ 2 - 1
bin/Makefile.am

@@ -4,7 +4,8 @@ bin_PROGRAMS += \
 bin_ytree_SOURCES = \
 	bin/ytree.c \
 	src/sr_copypaste.c \
-	src/pline.c
+	src/pline.c \
+	src/show.c
 
 #bin_klish_klish_LDADD = \
 #	libklish.la \

+ 3 - 5
configure.ac

@@ -4,10 +4,8 @@ m4_define([MAJOR_VERSION], 1)
 m4_define([MINOR_VERSION], 0)
 m4_define([MICRO_VERSION], 0)
 
-AC_PREREQ(2.59)
-AC_INIT([klish-plugin-sysrepo],
-        [MAJOR_VERSION.MINOR_VERSION.MICRO_VERSION],
-        [serj.kalichev at gmail dot com])
+AC_PREREQ([2.71])
+AC_INIT([klish-plugin-sysrepo],[MAJOR_VERSION.MINOR_VERSION.MICRO_VERSION],[serj.kalichev at gmail dot com])
 
 AC_CONFIG_AUX_DIR(aux_scripts)
 AC_CONFIG_MACRO_DIR([m4])
@@ -22,7 +20,7 @@ AC_USE_SYSTEM_EXTENSIONS
 
 # Checks for programs.
 AC_PROG_CC
-AC_PROG_LIBTOOL
+LT_INIT
 
 AC_CONFIG_HEADERS([config.h])
 AM_INIT_AUTOMAKE(subdir-objects)

+ 3 - 3
src/Makefile.am

@@ -5,7 +5,7 @@ plugin_LTLIBRARIES += kplugin-sysrepo.la
 kplugin_sysrepo_la_SOURCES =
 kplugin_sysrepo_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version -module
 kplugin_sysrepo_la_LIBS =
-kplugin_sysrepo_la_CFLAGS = $(AM_LDFLAGS)
+kplugin_sysrepo_la_CFLAGS = $(AM_CFLAGS)
 #kplugin_sysrepo_la_LIBADD = libsysrepo.la
 
 kplugin_sysrepo_la_SOURCES += \
@@ -13,6 +13,6 @@ kplugin_sysrepo_la_SOURCES += \
 	src/private.h \
 	src/syms.c \
 	src/sr_copypaste.c \
+	src/show.c \
 	src/pline.h \
-	src/pline.c \
-	src/show.c
+	src/pline.c

+ 2 - 4
src/pline.c

@@ -731,10 +731,8 @@ static bool_t pline_parse_module(const struct lys_module *module, faux_argv_t *a
 						key = faux_zmalloc(sizeof(*key));
 						assert(key);
 						key->node = iter;
-						if (leaf->dflt) {
-							const struct ly_ctx *ctx = sr_session_acquire_context(pline->sess);
-							key->dflt = lyd_value_get_canonical(ctx, leaf->dflt);
-							sr_session_release_context(pline->sess);
+						if ((key->dflt = klysc_node_ext_default(iter))) {
+syslog(LOG_ERR, "key dflt %s", key->dflt);
 							if (first_key)
 								first_key_is_optional = BOOL_TRUE;
 						}

+ 2 - 0
src/private.h

@@ -79,6 +79,8 @@ void show_subtree(const struct lyd_node *nodes_list, size_t level,
 // Sysrepo copy-paste
 int sr_module_is_internal(const struct lys_module *ly_mod);
 
+const char *klysc_node_ext_default(const struct lysc_node *node);
+
 C_DECL_END
 
 

+ 11 - 1
src/show.c

@@ -15,8 +15,8 @@
 #include <sysrepo/values.h>
 #include <libyang/tree_edit.h>
 
-#include "pline.h"
 #include "private.h"
+#include "pline.h"
 
 
 static void show_container(const struct lyd_node *node, size_t level,
@@ -86,6 +86,16 @@ const char *klysc_node_ext_completion(const struct lysc_node *node)
 }
 
 
+const char *klysc_node_ext_default(const struct lysc_node *node)
+{
+	const char *dflt = NULL;
+
+	klysc_node_ext(node, "klish", "default", &dflt);
+
+	return dflt;
+}
+
+
 static char *get_value(const struct lyd_node *node)
 {
 	const struct lysc_node *schema = NULL;

+ 6 - 0
yang/klish.yang

@@ -11,4 +11,10 @@ module klish {
   extension password {
     description "Leaf element contains password.";
   }
+
+  extension default {
+    argument "default";
+    description "Default value for list's key to make it optional.";
+  }
+
 }