virsh: Introduce net-update --section completer

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2022-01-10 12:44:23 +01:00
parent 687d6f1d7b
commit d724ca8fcd
4 changed files with 27 additions and 1 deletions

View File

@ -241,3 +241,23 @@ virshNetworkUpdateCommandCompleter(vshControl *ctl G_GNUC_UNUSED,
return ret; return ret;
} }
char **
virshNetworkUpdateSectionCompleter(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_SECTION_LAST);
/* The first item in the enum is not accepted by virsh. */
for (i = 1; i < VIR_NETWORK_SECTION_LAST; i++)
ret[i - 1] = g_strdup(virshNetworkSectionTypeToString(i));
return ret;
}

View File

@ -51,3 +51,8 @@ char **
virshNetworkUpdateCommandCompleter(vshControl *ctl, virshNetworkUpdateCommandCompleter(vshControl *ctl,
const vshCmd *cmd, const vshCmd *cmd,
unsigned int flags); unsigned int flags);
char **
virshNetworkUpdateSectionCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);

View File

@ -925,6 +925,7 @@ static const vshCmdOptDef opts_network_update[] = {
{.name = "section", {.name = "section",
.type = VSH_OT_DATA, .type = VSH_OT_DATA,
.flags = VSH_OFLAG_REQ, .flags = VSH_OFLAG_REQ,
.completer = virshNetworkUpdateSectionCompleter,
.help = N_("which section of network configuration to update") .help = N_("which section of network configuration to update")
}, },
{.name = "xml", {.name = "xml",
@ -948,7 +949,6 @@ VIR_ENUM_IMPL(virshNetworkUpdateCommand,
VIR_NETWORK_UPDATE_COMMAND_LAST, VIR_NETWORK_UPDATE_COMMAND_LAST,
"none", "modify", "delete", "add-last", "add-first"); "none", "modify", "delete", "add-last", "add-first");
VIR_ENUM_DECL(virshNetworkSection);
VIR_ENUM_IMPL(virshNetworkSection, VIR_ENUM_IMPL(virshNetworkSection,
VIR_NETWORK_SECTION_LAST, VIR_NETWORK_SECTION_LAST,
"none", "bridge", "domain", "ip", "ip-dhcp-host", "none", "bridge", "domain", "ip", "ip-dhcp-host",

View File

@ -45,5 +45,6 @@ typedef struct virshNetworkEventCallback virshNetworkEventCallback;
extern virshNetworkEventCallback virshNetworkEventCallbacks[]; extern virshNetworkEventCallback virshNetworkEventCallbacks[];
VIR_ENUM_DECL(virshNetworkUpdateCommand); VIR_ENUM_DECL(virshNetworkUpdateCommand);
VIR_ENUM_DECL(virshNetworkSection);
extern const vshCmdDef networkCmds[]; extern const vshCmdDef networkCmds[];