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

[libvirt] [v4 4/5] 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

v4
* rewritten using virStringSplit()

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

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 7747446..1406d2e 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -2796,7 +2796,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 271c841..cb89187 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -2630,6 +2630,12 @@ error:
 #endif
 }
 
+char **
+vshSuspendTargetCompleter(unsigned int unused_flags ATTRIBUTE_UNUSED)
+{
+    return virStringSplit("mem disk hybrid", " ", 0);
+}
+
 #ifdef USE_READLINE
 
 /* -----------------
diff --git a/tools/virsh.h b/tools/virsh.h
index 845fc17..c8e3d38 100644
--- a/tools/virsh.h
+++ b/tools/virsh.h
@@ -259,6 +259,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]