Browse Source

Separate symbols for show operations

Serj Kalichev 3 months ago
parent
commit
7bda9458ab
4 changed files with 100 additions and 3 deletions
  1. 29 0
      src/klish_plugin_sysrepo.h
  2. 12 0
      src/plugin.c
  3. 37 1
      src/syms.c
  4. 22 2
      xml/sysrepo.xml

+ 29 - 0
src/klish_plugin_sysrepo.h

@@ -114,6 +114,29 @@ typedef enum {
 		PAT_LEAFLIST |
 		PAT_LEAFLIST_VALUE,
 
+	PT_SHOW =
+		PAT_CONTAINER |
+		PAT_LIST |
+		PAT_LIST_KEY |
+		PAT_LIST_KEY_INCOMPLETED |
+		PAT_LEAF |
+		PAT_LEAF_EMPTY |
+		PAT_LEAFLIST |
+		PAT_LEAFLIST_VALUE,
+
+	PT_NOT_SHOW =
+		PAT_LEAF_VALUE,
+
+	PT_COMPL_SHOW =
+		PAT_CONTAINER |
+		PAT_LIST |
+		PAT_LIST_KEY |
+		PAT_LIST_KEY_INCOMPLETED |
+		PAT_LEAF |
+		PAT_LEAF_EMPTY |
+		PAT_LEAFLIST |
+		PAT_LEAFLIST_VALUE,
+
 } pt_e;
 
 
@@ -224,6 +247,8 @@ int srp_PLINE_EDIT(kcontext_t *context);
 int srp_PLINE_EDIT_ABS(kcontext_t *context);
 int srp_PLINE_INSERT_FROM(kcontext_t *context);
 int srp_PLINE_INSERT_TO(kcontext_t *context);
+int srp_PLINE_SHOW(kcontext_t *context);
+int srp_PLINE_SHOW_ABS(kcontext_t *context);
 
 // Completion/Help/Prompt
 int srp_compl(kcontext_t *context);
@@ -242,6 +267,10 @@ int srp_compl_insert_to(kcontext_t *context);
 int srp_help_insert_to(kcontext_t *context);
 int srp_prompt_edit_path(kcontext_t *context);
 int srp_compl_xpath(kcontext_t *context);
+int srp_compl_show(kcontext_t *context);
+int srp_compl_show_abs(kcontext_t *context);
+int srp_help_show(kcontext_t *context);
+int srp_help_show_abs(kcontext_t *context);
 
 // Operations
 int srp_set(kcontext_t *context);

+ 12 - 0
src/plugin.c

@@ -70,6 +70,10 @@ int kplugin_sysrepo_init(kcontext_t *context)
 		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC, KSYM_SILENT));
 	kplugin_add_syms(plugin, ksym_new_ext("PLINE_INSERT_TO", srp_PLINE_INSERT_TO,
 		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC, KSYM_SILENT));
+	kplugin_add_syms(plugin, ksym_new_ext("PLINE_SHOW", srp_PLINE_SHOW,
+		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC, KSYM_SILENT));
+	kplugin_add_syms(plugin, ksym_new_ext("PLINE_SHOW_ABS", srp_PLINE_SHOW_ABS,
+		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC, KSYM_SILENT));
 
 	// Completion/Help/Prompt
 	kplugin_add_syms(plugin, ksym_new_ext("srp_compl", srp_compl,
@@ -104,6 +108,14 @@ int kplugin_sysrepo_init(kcontext_t *context)
 		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC, KSYM_SILENT));
 	kplugin_add_syms(plugin, ksym_new_ext("srp_compl_xpath", srp_compl_xpath,
 		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC, KSYM_NONSILENT));
+	kplugin_add_syms(plugin, ksym_new_ext("srp_compl_show", srp_compl_show,
+		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC, KSYM_NONSILENT));
+	kplugin_add_syms(plugin, ksym_new_ext("srp_compl_show_abs", srp_compl_show_abs,
+		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC, KSYM_NONSILENT));
+	kplugin_add_syms(plugin, ksym_new_ext("srp_help_show", srp_help_show,
+		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC, KSYM_NONSILENT));
+	kplugin_add_syms(plugin, ksym_new_ext("srp_help_show_abs", srp_help_show_abs,
+		KSYM_USERDEFINED_PERMANENT, KSYM_SYNC, KSYM_NONSILENT));
 
 	// Operations
 	kplugin_add_syms(plugin, ksym_new_ext("srp_set", srp_set,

+ 37 - 1
src/syms.c

@@ -195,6 +195,30 @@ int srp_help_insert(kcontext_t *context)
 }
 
 
+int srp_compl_show(kcontext_t *context)
+{
+	return srp_compl_or_help(context, BOOL_FALSE, PT_COMPL_SHOW, BOOL_TRUE, BOOL_TRUE);
+}
+
+
+int srp_compl_show_abs(kcontext_t *context)
+{
+	return srp_compl_or_help(context, BOOL_FALSE, PT_COMPL_SHOW, BOOL_FALSE, BOOL_TRUE);
+}
+
+
+int srp_help_show(kcontext_t *context)
+{
+	return srp_compl_or_help(context, BOOL_TRUE, PT_COMPL_SHOW, BOOL_TRUE, BOOL_TRUE);
+}
+
+
+int srp_help_show_abs(kcontext_t *context)
+{
+	return srp_compl_or_help(context, BOOL_TRUE, PT_COMPL_SHOW, BOOL_FALSE, BOOL_TRUE);
+}
+
+
 int srp_prompt_edit_path(kcontext_t *context)
 {
 	faux_argv_t *cur_path = NULL;
@@ -289,6 +313,18 @@ int srp_PLINE_INSERT_FROM(kcontext_t *context)
 }
 
 
+int srp_PLINE_SHOW(kcontext_t *context)
+{
+	return srp_check_type(context, PT_NOT_SHOW, 1, BOOL_TRUE);
+}
+
+
+int srp_PLINE_SHOW_ABS(kcontext_t *context)
+{
+	return srp_check_type(context, PT_NOT_SHOW, 1, BOOL_FALSE);
+}
+
+
 static faux_argv_t *assemble_insert_to(sr_session_ctx_t *sess, const kpargv_t *pargv,
 	faux_argv_t *cur_path, const char *candidate_value, pline_opts_t *opts)
 {
@@ -920,7 +956,7 @@ static int show(kcontext_t *context, sr_datastore_t ds,
 			fprintf(stderr, ERRORMSG "Can't get expression\n");
 			goto err;
 		}
-		if (!(expr->pat & PT_EDIT)) {
+		if (!(expr->pat & PT_SHOW)) {
 			fprintf(stderr, ERRORMSG "Illegal expression for 'show' operation\n");
 			goto err;
 		}

+ 22 - 2
xml/sysrepo.xml

@@ -79,6 +79,26 @@
 	<ACTION sym="PLINE_INSERT_TO@sysrepo"/>
 </PTYPE>
 
+<PTYPE name="PLINE_SHOW">
+	<COMPL>
+		<ACTION sym="srp_compl_show@sysrepo"/>
+	</COMPL>
+	<HELP>
+		<ACTION sym="srp_help_show@sysrepo"/>
+	</HELP>
+	<ACTION sym="PLINE_SHOW@sysrepo"/>
+</PTYPE>
+
+<PTYPE name="PLINE_SHOW_ABS">
+	<COMPL>
+		<ACTION sym="srp_compl_show_abs@sysrepo"/>
+	</COMPL>
+	<HELP>
+		<ACTION sym="srp_help_show_abs@sysrepo"/>
+	</HELP>
+	<ACTION sym="PLINE_SHOW_ABS@sysrepo"/>
+</PTYPE>
+
 
 <VIEW name="main">
 
@@ -88,7 +108,7 @@
 
 	<COMMAND name="show" help="Show" mode="switch">
 		<COMMAND name="running" help="Show running-config">
-			<PARAM name="path" ptype="/PLINE_EDIT_ABS" min="0" max="100"/>
+			<PARAM name="path" ptype="/PLINE_SHOW_ABS" min="0" max="100"/>
 			<ACTION sym="srp_show_abs@sysrepo">running</ACTION>
 		</COMMAND>
 	</COMMAND>
@@ -168,7 +188,7 @@
 	</COMMAND>
 
 	<COMMAND name="show" help="Show data hierarchy">
-		<PARAM name="path" ptype="/PLINE_EDIT" min="0" max="100"/>
+		<PARAM name="path" ptype="/PLINE_SHOW" min="0" max="100"/>
 		<ACTION sym="srp_show@sysrepo"/>
 	</COMMAND>