Browse Source

Help for sysrepo Xpath. Enumeration for positional arguments type

Serj Kalichev 1 year ago
parent
commit
e755023ece
4 changed files with 54 additions and 2 deletions
  1. 38 0
      src/pline.h
  2. 1 0
      src/plugin.c
  3. 14 2
      src/syms.c
  4. 1 0
      src/syms.h

+ 38 - 0
src/pline.h

@@ -11,6 +11,44 @@
 #include <sysrepo.h>
 #include <sysrepo/xpath.h>
 
+// Type of positional pline argument
+// P(line) A(rg) T(ype)
+typedef enum {
+	PAT_NONE			= 0x0001,
+	PAT_CONTAINER			= 0x0002,
+	PAT_LIST			= 0x0004,
+	PAT_LIST_KEY			= 0x0008,
+	PAT_LIST_KEY_INCOMPLETED	= 0x0010,
+	PAT_LEAF			= 0x0020,
+	PAT_LEAF_VALUE			= 0x0040,
+	PAT_LEAFLIST			= 0x0080,
+	PAT_LEAFLIST_VALUE		= 0x0100,
+} pat_e;
+
+
+// Type of pline expression
+// P(line) T(ype)
+typedef enum {
+
+	PT_SET =
+		PAT_CONTAINER |
+		PAT_LIST_KEY |
+		PAT_LEAF_VALUE |
+		PAT_LEAFLIST_VALUE,
+
+	PT_DEL =
+		PAT_CONTAINER |
+		PAT_LIST_KEY |
+		PAT_LEAF |
+		PAT_LEAFLIST |
+		PAT_LEAFLIST_VALUE,
+
+	PT_EDIT =
+		PAT_CONTAINER |
+		PAT_LIST_KEY,
+
+} pt_e;
+
 
 // Plain EXPRession
 typedef struct {

+ 1 - 0
src/plugin.c

@@ -34,6 +34,7 @@ int kplugin_sysrepo_init(kcontext_t *context)
 
 	// Symbols
 	kplugin_add_syms(plugin, ksym_new("srp_compl", srp_compl));
+	kplugin_add_syms(plugin, ksym_new("srp_help", srp_help));
 	kplugin_add_syms(plugin, ksym_new("srp_set", srp_set));
 
 	return 0;

+ 14 - 2
src/syms.c

@@ -49,7 +49,7 @@ static faux_argv_t *param2argv(const kpargv_t *pargv, const char *entry_name)
 // Candidate from pargv contains possible begin of current word (that must be
 // completed). kpargv's list don't contain candidate but only already parsed
 // words.
-int srp_compl(kcontext_t *context)
+static int srp_compl_or_help(kcontext_t *context, bool_t help)
 {
 	faux_argv_t *args = NULL;
 	pline_t *pline = NULL;
@@ -70,7 +70,7 @@ int srp_compl(kcontext_t *context)
 	args = param2argv(kcontext_parent_pargv(context), entry_name);
 	pline = pline_parse(sess, args, 0);
 	faux_argv_free(args);
-	pline_print_completions(pline, BOOL_FALSE);
+	pline_print_completions(pline, help);
 	pline_free(pline);
 
 	sr_disconnect(conn);
@@ -79,6 +79,18 @@ int srp_compl(kcontext_t *context)
 }
 
 
+int srp_compl(kcontext_t *context)
+{
+	return srp_compl_or_help(context, BOOL_FALSE);
+}
+
+
+int srp_help(kcontext_t *context)
+{
+	return srp_compl_or_help(context, BOOL_TRUE);
+}
+
+
 int srp_set(kcontext_t *context)
 {
 	faux_argv_t *args = NULL;

+ 1 - 0
src/syms.h

@@ -12,6 +12,7 @@
 C_DECL_BEGIN
 
 int srp_compl(kcontext_t *context);
+int srp_help(kcontext_t *context);
 int srp_set(kcontext_t *context);
 
 C_DECL_END