[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCHv3 5/6] virsh: Add vshSuspendTargetCompleter



vshSuspendTargetCompleter returns targets available for suspend.

This completer can be used for the command option completion
(for dompmsuspend, etc.).

virsh> dompmsuspend --target <TAB>
mem      disk    hybrid
virsh> dompmsuspend --target h<TAB>
virsh> dompmsuspend --target hybrid
---
v2
* label cleanup renamed to error
* vshSuspendTargetCompleter added to opts_dom_pm_suspend

v3
* removed useless if
* used virStringFreeList() instead of iteration

 tools/virsh-domain.c |  3 ++-
 tools/virsh.c        | 23 +++++++++++++++++++++++
 tools/virsh.h        |  1 +
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 5b200a3..8a118ed 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -2756,7 +2756,8 @@ static const vshCmdOptDef opts_dom_pm_suspend[] = {
      .flags = VSH_OFLAG_REQ,
      .help = N_("mem(Suspend-to-RAM), "
                 "disk(Suspend-to-Disk), "
-                "hybrid(Hybrid-Suspend)")
+                "hybrid(Hybrid-Suspend)"),
+     .completer = vshSuspendTargetCompleter
     },
     {.name = NULL}
 };
diff --git a/tools/virsh.c b/tools/virsh.c
index ae2dd55..5a5e520 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -2553,6 +2553,29 @@ error:
     return NULL;
 }
 
+char **
+vshSuspendTargetCompleter(unsigned int unused_flags ATTRIBUTE_UNUSED)
+{
+    const char *targets[] = {"mem", "disk", "hybrid"};
+    const unsigned int targets_size = ARRAY_CARDINALITY(targets);
+    char **names = NULL;
+    size_t i;
+
+    names = vshMalloc(NULL, sizeof(char *) * (targets_size + 1));
+
+    for (i = 0; i < targets_size; i++) {
+        if (VIR_STRDUP(names[i], targets[i]) < 0)
+            goto error;
+    }
+
+    names[i] = NULL;
+    return names;
+
+error:
+    virStringFreeList(names);
+    return NULL;
+}
+
 /* -----------------
  * Readline stuff
  * -----------------
diff --git a/tools/virsh.h b/tools/virsh.h
index 68414e4..6767e65 100644
--- a/tools/virsh.h
+++ b/tools/virsh.h
@@ -256,6 +256,7 @@ struct _vshCmdGrp {
 };
 
 char **vshDomainCompleter(unsigned int flags);
+char **vshSuspendTargetCompleter(unsigned int unused_flags);
 
 void vshError(vshControl *ctl, const char *format, ...)
     ATTRIBUTE_FMT_PRINTF(2, 3);
-- 
1.8.3.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]