[libvirt] [PATCH v2 07/12] vshCompleter: Pass partially parsed command

Michal Privoznik mprivozn at redhat.com
Mon Nov 13 16:06:27 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 | 9 ++++++++-
 tools/vsh.h | 1 +
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/tools/vsh.c b/tools/vsh.c
index 3ed6bb916..9cf85b180 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -2863,9 +2863,16 @@ 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);
+                if (partial)
+                    partial->skipChecks = true;
                 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 51f8ef213..ae40fb4e8 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