Signed-off-by: Lin Ma <lma@xxxxxxxx> --- tools/virsh-completer-interface.c | 13 +++++++++---- tools/virsh-completer-interface.h | 4 ++++ tools/virsh-interface.c | 8 +++----- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/tools/virsh-completer-interface.c b/tools/virsh-completer-interface.c index 777bb22b0b..c24a2cea6c 100644 --- a/tools/virsh-completer-interface.c +++ b/tools/virsh-completer-interface.c @@ -38,7 +38,8 @@ virshInterfaceCompleter(vshControl *ctl, VIR_AUTOSTRINGLIST tmp = NULL; virCheckFlags(VIR_CONNECT_LIST_INTERFACES_ACTIVE | - VIR_CONNECT_LIST_INTERFACES_INACTIVE, + VIR_CONNECT_LIST_INTERFACES_INACTIVE | + VIRSH_INTERFACE_COMPLETER_MAC, NULL); if (!priv->conn || virConnectIsAlive(priv->conn) <= 0) @@ -50,9 +51,13 @@ virshInterfaceCompleter(vshControl *ctl, tmp = g_new0(char *, nifaces + 1); for (i = 0; i < nifaces; i++) { - const char *name = virInterfaceGetName(ifaces[i]); - - tmp[i] = g_strdup(name); + if (!(flags & VIRSH_INTERFACE_COMPLETER_MAC)) { + const char *name = virInterfaceGetName(ifaces[i]); + tmp[i] = g_strdup(name); + } else { + const char *mac = virInterfaceGetMACString(ifaces[i]); + tmp[i] = g_strdup(mac); + } } ret = g_steal_pointer(&tmp); diff --git a/tools/virsh-completer-interface.h b/tools/virsh-completer-interface.h index 2b382222d7..71bc44c4b9 100644 --- a/tools/virsh-completer-interface.h +++ b/tools/virsh-completer-interface.h @@ -22,6 +22,10 @@ #include "vsh.h" +enum { + VIRSH_INTERFACE_COMPLETER_MAC = 1 << 0, +}; + char ** virshInterfaceCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index df97b74c4c..1dabc6e406 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -404,11 +404,9 @@ static const vshCmdInfo info_interface_name[] = { }; static const vshCmdOptDef opts_interface_name[] = { - {.name = "interface", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("interface mac") - }, + VIRSH_COMMON_OPT_INTERFACE(N_("interface mac"), + VIR_CONNECT_LIST_INTERFACES_ACTIVE | + VIRSH_INTERFACE_COMPLETER_MAC), {.name = NULL} }; -- 2.26.0