]> xenbits.xensource.com Git - libvirt.git/commitdiff
tools: Pass opaque data in vshCompleter and introduce autoCompleteOpaque
authorNishith Shah <nishithshah.2211@gmail.com>
Tue, 6 Sep 2016 12:04:37 +0000 (12:04 +0000)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 6 Sep 2016 15:46:40 +0000 (17:46 +0200)
This patch changes the signature of vshCompleters, allowing to pass along
some data that we might want to along with the completers; for example,
we might want to pass the autocomplete vshControl along with the
completer, in case the completer requires a connection to libvirtd.

Signed-off-by: Nishith Shah <nishithshah.2211@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
tools/vsh.c
tools/vsh.h

index 31579228b003020bc2f9be137b3aebb082e3fea3..be6a073f5678da10df1044bcf3501169f313a6e2 100644 (file)
 # define SA_SIGINFO 0
 #endif
 
+#ifdef WITH_READLINE
+/* For autocompletion */
+void *autoCompleteOpaque;
+#endif
+
 /* NOTE: It would be much nicer to have these two as part of vshControl
  * structure, unfortunately readline doesn't support passing opaque data
  * and only relies on static data accessible from the user-side callback
@@ -2808,7 +2813,8 @@ vshReadlineParse(const char *text, int state)
         res = vshReadlineOptionsGenerator(sanitized_text, state, cmd);
     } else if (non_bool_opt_exists && data_complete && opt->completer) {
         if (!completed_list)
-            completed_list = opt->completer(opt->completer_flags);
+            completed_list = opt->completer(autoCompleteOpaque,
+                                            opt->completer_flags);
         if (completed_list) {
             while ((completed_name = completed_list[completed_list_index])) {
                 completed_list_index++;
@@ -2858,6 +2864,9 @@ vshReadlineInit(vshControl *ctl)
     char *histsize_env = NULL;
     const char *histsize_str = NULL;
 
+    /* Opaque data for autocomplete callbacks. */
+    autoCompleteOpaque = ctl;
+
     /* Allow conditional parsing of the ~/.inputrc file.
      * Work around ancient readline 4.1 (hello Mac OS X),
      * which declared it as 'char *' instead of 'const char *'.
index 7f430552e27f7617121ab0494f6b02f12973a76a..e53910f9afbd9ec8413e56541cd9a49069dc25e8 100644 (file)
@@ -123,7 +123,7 @@ typedef struct _vshCmdOpt vshCmdOpt;
 typedef struct _vshCmdOptDef vshCmdOptDef;
 typedef struct _vshControl vshControl;
 
-typedef char **(*vshCompleter)(unsigned int flags);
+typedef char **(*vshCompleter)(void *opaque, unsigned int flags);
 
 /*
  * vshCmdInfo -- name/value pair for information about command