[v4 4/5] virsh: Add vshSuspendTargetCompleter

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

 



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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]