Re: [libvirt] [ [PATCH v3 4/8] virsh: Add event name completion to 'event' command

2018-05-24 Thread Michal Privoznik
On 05/23/2018 08:32 AM, Lin Ma wrote:
> Signed-off-by: Lin Ma 
> ---
>  tools/virsh-completer.c | 31 +++
>  tools/virsh-completer.h |  3 +++
>  tools/virsh-domain.c|  1 +
>  3 files changed, 35 insertions(+)
> 
> diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c
> index b402fd22c3..c0c3c5571a 100644
> --- a/tools/virsh-completer.c
> +++ b/tools/virsh-completer.c
> @@ -23,6 +23,7 @@
>  #include 
>  
>  #include "virsh-completer.h"
> +#include "virsh-domain.h"
>  #include "virsh.h"
>  #include "virsh-pool.h"
>  #include "virsh-util.h"
> @@ -676,3 +677,33 @@ virshSecretEventNameCompleter(vshControl *ctl 
> ATTRIBUTE_UNUSED,
>  virStringListFree(ret);
>  return NULL;
>  }
> +
> +
> +char **
> +virshEventNameCompleter(vshControl *ctl,
> +const vshCmd *cmd ATTRIBUTE_UNUSED,
> +unsigned int flags)
> +{
> +virshControlPtr priv = ctl->privData;
> +size_t i = 0;
> +char **ret = NULL;
> +
> +virCheckFlags(0, NULL);
> +
> +if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
> +return NULL;

There is no need for connection.

> +
> +if (VIR_ALLOC_N(ret, VIR_DOMAIN_EVENT_ID_LAST + 1) < 0)
> +goto error;
> +
> +for (i = 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++) {
> +if (VIR_STRDUP(ret[i], vshEventCallbacks[i].name) < 0)
> +goto error;
> +}
> +
> +return ret;
> +
> + error:
> +virStringListFree(ret);
> +return NULL;
> +}

Michal

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


[libvirt] [ [PATCH v3 4/8] virsh: Add event name completion to 'event' command

2018-05-23 Thread Lin Ma
Signed-off-by: Lin Ma 
---
 tools/virsh-completer.c | 31 +++
 tools/virsh-completer.h |  3 +++
 tools/virsh-domain.c|  1 +
 3 files changed, 35 insertions(+)

diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c
index b402fd22c3..c0c3c5571a 100644
--- a/tools/virsh-completer.c
+++ b/tools/virsh-completer.c
@@ -23,6 +23,7 @@
 #include 
 
 #include "virsh-completer.h"
+#include "virsh-domain.h"
 #include "virsh.h"
 #include "virsh-pool.h"
 #include "virsh-util.h"
@@ -676,3 +677,33 @@ virshSecretEventNameCompleter(vshControl *ctl 
ATTRIBUTE_UNUSED,
 virStringListFree(ret);
 return NULL;
 }
+
+
+char **
+virshEventNameCompleter(vshControl *ctl,
+const vshCmd *cmd ATTRIBUTE_UNUSED,
+unsigned int flags)
+{
+virshControlPtr priv = ctl->privData;
+size_t i = 0;
+char **ret = NULL;
+
+virCheckFlags(0, NULL);
+
+if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+return NULL;
+
+if (VIR_ALLOC_N(ret, VIR_DOMAIN_EVENT_ID_LAST + 1) < 0)
+goto error;
+
+for (i = 0; i < VIR_DOMAIN_EVENT_ID_LAST; i++) {
+if (VIR_STRDUP(ret[i], vshEventCallbacks[i].name) < 0)
+goto error;
+}
+
+return ret;
+
+ error:
+virStringListFree(ret);
+return NULL;
+}
diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h
index c662267882..9f8dc3dfa8 100644
--- a/tools/virsh-completer.h
+++ b/tools/virsh-completer.h
@@ -73,6 +73,9 @@ char ** virshSecretUUIDCompleter(vshControl *ctl,
 char ** virshSnapshotNameCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);
+char ** virshEventNameCompleter(vshControl *ctl,
+const vshCmd *cmd,
+unsigned int flags);
 
 char ** virshAllocpagesPagesizeCompleter(vshControl *ctl,
 const vshCmd *cmd,
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 347c744bc9..4af7aa2155 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -13339,6 +13339,7 @@ static const vshCmdOptDef opts_event[] = {
   0),
 {.name = "event",
  .type = VSH_OT_STRING,
+ .completer = virshEventNameCompleter,
  .help = N_("which event type to wait for")
 },
 {.name = "all",
-- 
2.16.2

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