]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Introduce net-update --command completer
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 10 Jan 2022 11:41:03 +0000 (12:41 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 19 Jan 2022 15:48:33 +0000 (16:48 +0100)
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tools/virsh-completer-network.c
tools/virsh-completer-network.h
tools/virsh-network.c
tools/virsh-network.h

index d498f59cb883359582f1b07727dc62d1a4f983b2..d0cf80f22cb0af3cf8667992a34f1593119c1071 100644 (file)
@@ -218,3 +218,26 @@ virshNetworkDhcpMacCompleter(vshControl *ctl,
     }
     return ret;
 }
+
+
+char **
+virshNetworkUpdateCommandCompleter(vshControl *ctl G_GNUC_UNUSED,
+                                   const vshCmd *cmd G_GNUC_UNUSED,
+                                   unsigned int flags)
+{
+    char **ret = NULL;
+    size_t i;
+
+    virCheckFlags(0, NULL);
+
+    ret = g_new0(char *, VIR_NETWORK_UPDATE_COMMAND_LAST + 1);
+
+    /* The first item in the enum is not accepted by virsh, But there's "add"
+     * which is accepted an is just an alias to "add-last". */
+    ret[0] = g_strdup("add");
+
+    for (i = 1; i < VIR_NETWORK_UPDATE_COMMAND_LAST; i++)
+        ret[i] = g_strdup(virshNetworkUpdateCommandTypeToString(i));
+
+    return ret;
+}
index ffcda683550b7d81b8cf1792b6d530785cd3dfe0..7557dfdb0dc23b237a93e42de5b9987256e12cd7 100644 (file)
@@ -46,3 +46,8 @@ char **
 virshNetworkDhcpMacCompleter(vshControl *ctl,
                              const vshCmd *cmd,
                              unsigned int flags);
+
+char **
+virshNetworkUpdateCommandCompleter(vshControl *ctl,
+                                   const vshCmd *cmd,
+                                   unsigned int flags);
index 02b22bf91276da4168a970d26b83ef06251fc92d..2a0a24c6d3f5ef2b006a0e8bedeb40dc5ccb4885 100644 (file)
@@ -919,6 +919,7 @@ static const vshCmdOptDef opts_network_update[] = {
     {.name = "command",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
+     .completer = virshNetworkUpdateCommandCompleter,
      .help = N_("type of update (add-first, add-last (add), delete, or modify)")
     },
     {.name = "section",
@@ -943,7 +944,6 @@ static const vshCmdOptDef opts_network_update[] = {
     {.name = NULL}
 };
 
-VIR_ENUM_DECL(virshNetworkUpdateCommand);
 VIR_ENUM_IMPL(virshNetworkUpdateCommand,
               VIR_NETWORK_UPDATE_COMMAND_LAST,
               "none", "modify", "delete", "add-last", "add-first");
index 3c786dd7a194a07301eaab22fbdab93744d0caad..05da736cce1588b6efe9ab330eae406557f714f5 100644 (file)
@@ -44,4 +44,6 @@ typedef struct virshNetworkEventCallback virshNetworkEventCallback;
 
 extern virshNetworkEventCallback virshNetworkEventCallbacks[];
 
+VIR_ENUM_DECL(virshNetworkUpdateCommand);
+
 extern const vshCmdDef networkCmds[];