virsh: Introduce net-update --command 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:41:03 +01:00
parent ab96031943
commit 687d6f1d7b
4 changed files with 31 additions and 1 deletions

View File

@ -218,3 +218,26 @@ virshNetworkDhcpMacCompleter(vshControl *ctl,
} }
return ret; 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;
}

View File

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

View File

@ -919,6 +919,7 @@ static const vshCmdOptDef opts_network_update[] = {
{.name = "command", {.name = "command",
.type = VSH_OT_DATA, .type = VSH_OT_DATA,
.flags = VSH_OFLAG_REQ, .flags = VSH_OFLAG_REQ,
.completer = virshNetworkUpdateCommandCompleter,
.help = N_("type of update (add-first, add-last (add), delete, or modify)") .help = N_("type of update (add-first, add-last (add), delete, or modify)")
}, },
{.name = "section", {.name = "section",
@ -943,7 +944,6 @@ static const vshCmdOptDef opts_network_update[] = {
{.name = NULL} {.name = NULL}
}; };
VIR_ENUM_DECL(virshNetworkUpdateCommand);
VIR_ENUM_IMPL(virshNetworkUpdateCommand, 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");

View File

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