[PATCH 11/14] virsh: completer: Introduce dummy completer for local files

Peter Krempa pkrempa at redhat.com
Thu Sep 16 17:10:42 UTC 2021


For now the completion does the correct thing of completing a local path
if NULL is returned.

Introduce 'virshCompletePathLocalExisting' and use it in the
'VIRSH_COMMON_OPT_FILE' macro.

This for now serves as an annotation for the function which want to read
a file on the host running virsh. In the future this can be used with a
more sophisticated implementation.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 tools/virsh-completer.c | 17 +++++++++++++++++
 tools/virsh-completer.h |  5 +++++
 tools/virsh.h           |  1 +
 3 files changed, 23 insertions(+)

diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c
index 57e0c3905c..100f206598 100644
--- a/tools/virsh-completer.c
+++ b/tools/virsh-completer.c
@@ -128,3 +128,20 @@ virshCommaStringListComplete(const char *input,

     return g_steal_pointer(&ret);
 }
+
+
+/**
+ * virshCompletePathLocalExisting:
+ *
+ * Complete a path to a existing file used as input. The file is used as input
+ * for virsh so only local files are considered.
+ *
+ * Note: For now this is a no-op. Readline does the correct thing.
+ */
+char **
+virshCompletePathLocalExisting(vshControl *ctl G_GNUC_UNUSED,
+                               const vshCmd *cmd G_GNUC_UNUSED,
+                               unsigned int completerflags G_GNUC_UNUSED)
+{
+    return NULL;
+}
diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h
index 1243a13a5e..9a77aa117f 100644
--- a/tools/virsh-completer.h
+++ b/tools/virsh-completer.h
@@ -35,3 +35,8 @@
 char **
 virshCommaStringListComplete(const char *input,
                              const char **options);
+
+char **
+virshCompletePathLocalExisting(vshControl *ctl,
+                               const vshCmd *cmd,
+                               unsigned int completerflags);
diff --git a/tools/virsh.h b/tools/virsh.h
index 8e1b8ced90..cacd54db57 100644
--- a/tools/virsh.h
+++ b/tools/virsh.h
@@ -100,6 +100,7 @@
     {.name = "file", \
      .type = VSH_OT_DATA, \
      .flags = VSH_OFLAG_REQ, \
+     .completer = virshCompletePathLocalExisting, \
      .help = _helpstr \
     }

-- 
2.31.1




More information about the libvir-list mailing list