[libvirt] [PATCH 06/11] vshCompleter: Pass partially parsed command

Michal Privoznik mprivozn at redhat.com
Tue Nov 7 12:22:54 UTC 2017


The callback we're calling might need to make decisions on
already passed arguments. For instance, a completer that is
supposed to bring up list of domain's interfaces might want to
see what domain user wants to work with.

Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
 tools/vsh.c | 7 ++++++-
 tools/vsh.h | 1 +
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/vsh.c b/tools/vsh.c
index dd2f06ada..121669574 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -2859,9 +2859,14 @@ vshReadlineParse(const char *text, int state)
         }
 
         if (!complete_opts && complete_data) {
-            if (!completed_list && opt && opt->completer)
+            if (!completed_list && opt && opt->completer) {
+                vshCmd *partial = NULL;
+                vshCommandStringParse(autoCompleteOpaque, rl_line_buffer, &partial);
                 completed_list = opt->completer(autoCompleteOpaque,
+                                                partial,
                                                 opt->completer_flags);
+                vshCommandFree(partial);
+            }
             if (completed_list) {
                 while ((completed_name = completed_list[completed_list_index])) {
                     completed_list_index++;
diff --git a/tools/vsh.h b/tools/vsh.h
index 1ebd5c11a..c5a62e593 100644
--- a/tools/vsh.h
+++ b/tools/vsh.h
@@ -124,6 +124,7 @@ typedef struct _vshCmdOptDef vshCmdOptDef;
 typedef struct _vshControl vshControl;
 
 typedef char **(*vshCompleter)(vshControl *ctl,
+                               const vshCmd *cmd,
                                unsigned int flags);
 
 /*
-- 
2.13.6




More information about the libvir-list mailing list