'--storage' of the 'undefine' command and '--migrate-disks' of
the
'migrate' command take a list of disk targets as an argument.
We can simply combine 'virshDomainDiskTargetCompleter' with
'virshCommaStringListComplete' to provide the completions.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
tools/virsh-completer-domain.c | 36 ++++++++++++++++++++++++++++++++++
tools/virsh-completer-domain.h | 10 ++++++++++
tools/virsh-domain.c | 2 ++
3 files changed, 48 insertions(+)
diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c
index 3ef6c82388..34985f6281 100644
--- a/tools/virsh-completer-domain.c
+++ b/tools/virsh-completer-domain.c
@@ -220,6 +220,42 @@ virshDomainDiskTargetCompleter(vshControl *ctl,
}
+static char **
+virshDomainDiskTargetListCompleter(vshControl *ctl,
+ const vshCmd *cmd,
+ const char *argname)
+{
+ const char *curval = NULL;
+ g_auto(GStrv) targets = virshDomainDiskTargetCompleter(ctl, cmd, 0);
+
+ if (vshCommandOptStringQuiet(ctl, cmd, argname, &curval) < 0)
+ return NULL;
+
+ if (!targets)
+ return NULL;
+
+ return virshCommaStringListComplete(curval, (const char **) targets);
+}
+
+
+char **
+virshDomainMigrateDisksCompleter(vshControl *ctl,
+ const vshCmd *cmd,
+ unsigned int completeflags G_GNUC_UNUSED)
+{
+ return virshDomainDiskTargetListCompleter(ctl, cmd, "migrate-disks");
+}
+
+
+char **
+virshDomainUndefineStorageDisksCompleter(vshControl *ctl,
+ const vshCmd *cmd,
+ unsigned int completeflags G_GNUC_UNUSED)
+{
+ return virshDomainDiskTargetListCompleter(ctl, cmd, "storage");
+}
+
+
char **
virshDomainEventNameCompleter(vshControl *ctl G_GNUC_UNUSED,
const vshCmd *cmd G_GNUC_UNUSED,
diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h
index f23ec2735f..1ed3f94094 100644
--- a/tools/virsh-completer-domain.h
+++ b/tools/virsh-completer-domain.h
@@ -166,3 +166,13 @@ char **
virshDomainStorageFileFormatCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);
+
+char **
+virshDomainMigrateDisksCompleter(vshControl *ctl,
+ const vshCmd *cmd,
+ unsigned int completeflags);
+
+char **
+virshDomainUndefineStorageDisksCompleter(vshControl *ctl,
+ const vshCmd *cmd,
+ unsigned int completeflags);
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 4d328d2174..05fa5c07f6 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -3552,6 +3552,7 @@ static const vshCmdOptDef opts_undefine[] = {
},
{.name = "storage",
.type = VSH_OT_STRING,
+ .completer = virshDomainUndefineStorageDisksCompleter,
.help = N_("remove associated storage volumes (comma separated list of "
"targets or source paths) (see domblklist)")
},
@@ -10371,6 +10372,7 @@ static const vshCmdOptDef opts_migrate[] = {
},
{.name = "migrate-disks",
.type = VSH_OT_STRING,
+ .completer = virshDomainMigrateDisksCompleter,
.help = N_("comma separated list of disks to be migrated")
},
{.name = "disks-port",
--
2.31.1