Browse Source

Two different syms to show datastore with current path or without it

Serj Kalichev 6 months ago
parent
commit
74b5f46915
4 changed files with 25 additions and 7 deletions
  1. 2 0
      src/plugin.c
  2. 1 0
      src/private.h
  3. 20 6
      src/syms.c
  4. 2 1
      xml/sysrepo.xml

+ 2 - 0
src/plugin.c

@@ -107,6 +107,8 @@ int kplugin_sysrepo_init(kcontext_t *context)
 		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
 	kplugin_add_syms(plugin, ksym_new_ext("srp_show", srp_show,
 		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
+	kplugin_add_syms(plugin, ksym_new_ext("srp_show_cur_path", srp_show_cur_path,
+		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
 	kplugin_add_syms(plugin, ksym_new_ext("srp_diff", srp_diff,
 		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC));
 	kplugin_add_syms(plugin, ksym_new_ext("srp_deactivate", srp_deactivate,

+ 1 - 0
src/private.h

@@ -63,6 +63,7 @@ int srp_verify(kcontext_t *context);
 int srp_commit(kcontext_t *context);
 int srp_reset(kcontext_t *context);
 int srp_show(kcontext_t *context);
+int srp_show_cur_path(kcontext_t *context);
 int srp_diff(kcontext_t *context);
 int srp_deactivate(kcontext_t *context);
 

+ 20 - 6
src/syms.c

@@ -856,7 +856,8 @@ err:
 }
 
 
-static int show(kcontext_t *context, sr_datastore_t ds)
+static int show(kcontext_t *context, sr_datastore_t ds,
+	const char *path_var, bool_t use_cur_path)
 {
 	int ret = -1;
 	faux_argv_t *args = NULL;
@@ -871,10 +872,11 @@ static int show(kcontext_t *context, sr_datastore_t ds)
 	sess = srp_udata_sr_sess(context);
 	if (ds != SRP_REPO_EDIT)
 		sr_session_switch_ds(sess, ds);
-	cur_path = (faux_argv_t *)srp_udata_path(context);
+	if (use_cur_path)
+		cur_path = (faux_argv_t *)srp_udata_path(context);
 
-	if (kpargv_find(kcontext_pargv(context), "path") || cur_path) {
-		args = param2argv(cur_path, kcontext_pargv(context), "path");
+	if (kpargv_find(kcontext_pargv(context), path_var) || cur_path) {
+		args = param2argv(cur_path, kcontext_pargv(context), path_var);
 		pline = pline_parse(sess, args, srp_udata_opts(context));
 		faux_argv_free(args);
 
@@ -915,7 +917,7 @@ err:
 }
 
 
-int srp_show(kcontext_t *context)
+static int show_path(kcontext_t *context, bool_t use_cur_path)
 {
 	sr_datastore_t ds = SRP_REPO_EDIT;
 	const char *script = NULL;
@@ -926,7 +928,19 @@ int srp_show(kcontext_t *context)
 		if (!kly_str2ds(script, strlen(script), &ds))
 			ds = SRP_REPO_EDIT;
 
-	return show(context, ds);
+	return show(context, ds, "path", use_cur_path);
+}
+
+
+int srp_show(kcontext_t *context)
+{
+	return show_path(context, BOOL_FALSE);
+}
+
+
+int srp_show_cur_path(kcontext_t *context)
+{
+	return show_path(context, BOOL_TRUE);
 }
 
 

+ 2 - 1
xml/sysrepo.xml

@@ -78,6 +78,7 @@
 
 	<COMMAND name="show" help="Show" mode="switch">
 		<COMMAND name="running" help="Show running-config">
+			<PARAM name="path" ptype="/PLINE_EDIT" min="0" max="100"/>
 			<ACTION sym="srp_show@sysrepo">running</ACTION>
 		</COMMAND>
 	</COMMAND>
@@ -158,7 +159,7 @@
 
 	<COMMAND name="show" help="Show data hierarchy">
 		<PARAM name="path" ptype="/PLINE_EDIT" min="0" max="100"/>
-		<ACTION sym="srp_show@sysrepo"/>
+		<ACTION sym="srp_show_cur_path@sysrepo"/>
 	</COMMAND>
 
 	<COMMAND name="diff" help="Show diff relative running-config">