From: Radoslaw Smigielski <[email protected]>

Add enum and static-list completers for 'attach-disk' options
targetbus, type, cache, io, mode, and sourcetype, and reuse the
existing storage file format completer for subdriver.

Partially-fixes: https://gitlab.com/libvirt/libvirt/-/work_items/9
Signed-off-by: Radoslaw Smigielski <[email protected]>

---
 tools/virsh-completer-domain.c | 74 ++++++++++++++++++++++++++++++++++
 tools/virsh-completer-domain.h | 30 ++++++++++++++
 tools/virsh-domain.c           |  7 ++++
 3 files changed, 111 insertions(+)

diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c
index 65b02488bb39..7251d70e997e 100644
--- a/tools/virsh-completer-domain.c
+++ b/tools/virsh-completer-domain.c
@@ -1180,3 +1180,77 @@ virshDomainXMLNativeFormatCompleter(vshControl *ctl,
 
     return vshCommaStringListComplete(NULL, formats);
 }
+
+
+char **
+virshDomainDiskBusCompleter(vshControl *ctl G_GNUC_UNUSED,
+                            const vshCmd *cmd G_GNUC_UNUSED,
+                            unsigned int flags)
+{
+    virCheckFlags(0, NULL);
+
+    return vshEnumComplete(VIR_DOMAIN_DISK_BUS_LAST,
+                           virDomainDiskBusTypeToString);
+}
+
+
+char **
+virshDomainDiskDeviceTypeCompleter(vshControl *ctl G_GNUC_UNUSED,
+                                   const vshCmd *cmd G_GNUC_UNUSED,
+                                   unsigned int flags)
+{
+    virCheckFlags(0, NULL);
+
+    return vshEnumComplete(VIR_DOMAIN_DISK_DEVICE_LAST,
+                           virDomainDiskDeviceTypeToString);
+}
+
+
+char **
+virshDomainDiskCacheCompleter(vshControl *ctl G_GNUC_UNUSED,
+                              const vshCmd *cmd G_GNUC_UNUSED,
+                              unsigned int flags)
+{
+    virCheckFlags(0, NULL);
+
+    return vshEnumComplete(VIR_DOMAIN_DISK_CACHE_LAST,
+                           virDomainDiskCacheTypeToString);
+}
+
+
+char **
+virshDomainDiskIoCompleter(vshControl *ctl G_GNUC_UNUSED,
+                           const vshCmd *cmd G_GNUC_UNUSED,
+                           unsigned int flags)
+{
+    virCheckFlags(0, NULL);
+
+    return vshEnumComplete(VIR_DOMAIN_DISK_IO_LAST,
+                           virDomainDiskIoTypeToString);
+}
+
+
+char **
+virshDomainAttachDiskModeCompleter(vshControl *ctl G_GNUC_UNUSED,
+                                   const vshCmd *cmd G_GNUC_UNUSED,
+                                   unsigned int flags)
+{
+    static const char *modes[] = {"readonly", "shareable", NULL};
+
+    virCheckFlags(0, NULL);
+
+    return vshCommaStringListComplete(NULL, modes);
+}
+
+
+char **
+virshDomainAttachDiskSourceTypeCompleter(vshControl *ctl G_GNUC_UNUSED,
+                                         const vshCmd *cmd G_GNUC_UNUSED,
+                                         unsigned int flags)
+{
+    static const char *types[] = {"file", "block", "network", NULL};
+
+    virCheckFlags(0, NULL);
+
+    return vshCommaStringListComplete(NULL, types);
+}
diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h
index 40de90afb79f..aa2e82649071 100644
--- a/tools/virsh-completer-domain.h
+++ b/tools/virsh-completer-domain.h
@@ -214,3 +214,33 @@ char **
 virshDomainXMLNativeFormatCompleter(vshControl *ctl,
                                     const vshCmd *cmd,
                                     unsigned int flags);
+
+char **
+virshDomainDiskBusCompleter(vshControl *ctl,
+                            const vshCmd *cmd,
+                            unsigned int flags);
+
+char **
+virshDomainDiskDeviceTypeCompleter(vshControl *ctl,
+                                   const vshCmd *cmd,
+                                   unsigned int flags);
+
+char **
+virshDomainDiskCacheCompleter(vshControl *ctl,
+                              const vshCmd *cmd,
+                              unsigned int flags);
+
+char **
+virshDomainDiskIoCompleter(vshControl *ctl,
+                           const vshCmd *cmd,
+                           unsigned int flags);
+
+char **
+virshDomainAttachDiskModeCompleter(vshControl *ctl,
+                                   const vshCmd *cmd,
+                                   unsigned int flags);
+
+char **
+virshDomainAttachDiskSourceTypeCompleter(vshControl *ctl,
+                                         const vshCmd *cmd,
+                                         unsigned int flags);
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index bd6c877b4521..ca35e3b7b214 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -435,6 +435,7 @@ static const vshCmdOptDef opts_attach_disk[] = {
     },
     {.name = "targetbus",
      .type = VSH_OT_STRING,
+     .completer = virshDomainDiskBusCompleter,
      .help = N_("target bus of disk device")
     },
     {.name = "driver",
@@ -443,6 +444,7 @@ static const vshCmdOptDef opts_attach_disk[] = {
     },
     {.name = "subdriver",
      .type = VSH_OT_STRING,
+     .completer = virshDomainStorageFileFormatCompleter,
      .help = N_("subdriver of disk device")
     },
     {.name = "iothread",
@@ -452,14 +454,17 @@ static const vshCmdOptDef opts_attach_disk[] = {
     },
     {.name = "cache",
      .type = VSH_OT_STRING,
+     .completer = virshDomainDiskCacheCompleter,
      .help = N_("cache mode of disk device")
     },
     {.name = "io",
      .type = VSH_OT_STRING,
+     .completer = virshDomainDiskIoCompleter,
      .help = N_("io policy of disk device")
     },
     {.name = "type",
      .type = VSH_OT_STRING,
+     .completer = virshDomainDiskDeviceTypeCompleter,
      .help = N_("target device type")
     },
     {.name = "shareable",
@@ -468,10 +473,12 @@ static const vshCmdOptDef opts_attach_disk[] = {
     },
     {.name = "mode",
      .type = VSH_OT_STRING,
+     .completer = virshDomainAttachDiskModeCompleter,
      .help = N_("mode of device reading and writing")
     },
     {.name = "sourcetype",
      .type = VSH_OT_STRING,
+     .completer = virshDomainAttachDiskSourceTypeCompleter,
      .help = N_("type of source (block|file|network)")
     },
     {.name = "serial",
-- 
2.54.0

Reply via email to