Rather than continually cut-n-paste the strings into each command,
create common macros to be used generically.  For virsh-volume, there
are 3 different types of "pool" options - 2 for create, 2 required
for the command, and 10 for string type options.

Signed-off-by: John Ferlan <jfer...@redhat.com>
---
 tools/virsh-volume.c | 94 +++++++++++++++++++---------------------------------
 1 file changed, 34 insertions(+), 60 deletions(-)

diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c
index 3408bee..b88d4c4 100644
--- a/tools/virsh-volume.c
+++ b/tools/virsh-volume.c
@@ -42,6 +42,26 @@
 #include "virxml.h"
 #include "virstring.h"
 
+#define VSH_VOLUME_POOL_CREATE_OPT_COMMON                  \
+    {.name = "pool",                                       \
+     .type = VSH_OT_DATA,                                  \
+     .flags = VSH_OFLAG_REQ,                               \
+     .help = N_("pool name")                               \
+    }                                                      \
+
+#define VSH_VOLUME_POOL_REQ_OPT_COMMON                     \
+    {.name = "pool",                                       \
+     .type = VSH_OT_DATA,                                  \
+     .flags = VSH_OFLAG_REQ,                               \
+     .help = N_("pool name or uuid")                       \
+    }                                                      \
+
+#define VSH_VOLUME_POOL_STRING_OPT_COMMON                  \
+    {.name = "pool",                                       \
+     .type = VSH_OT_STRING,                                \
+     .help = N_("pool name or uuid")                       \
+    }                                                      \
+
 virStorageVolPtr
 virshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd,
                      const char *optname,
@@ -145,11 +165,7 @@ static const vshCmdInfo info_vol_create_as[] = {
 };
 
 static const vshCmdOptDef opts_vol_create_as[] = {
-    {.name = "pool",
-     .type = VSH_OT_DATA,
-     .flags = VSH_OFLAG_REQ,
-     .help = N_("pool name")
-    },
+    VSH_VOLUME_POOL_CREATE_OPT_COMMON,
     {.name = "name",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
@@ -353,11 +369,7 @@ static const vshCmdInfo info_vol_create[] = {
 };
 
 static const vshCmdOptDef opts_vol_create[] = {
-    {.name = "pool",
-     .type = VSH_OT_DATA,
-     .flags = VSH_OFLAG_REQ,
-     .help = N_("pool name")
-    },
+    VSH_VOLUME_POOL_CREATE_OPT_COMMON,
     {.name = "file",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
@@ -423,11 +435,7 @@ static const vshCmdInfo info_vol_create_from[] = {
 };
 
 static const vshCmdOptDef opts_vol_create_from[] = {
-    {.name = "pool",
-     .type = VSH_OT_DATA,
-     .flags = VSH_OFLAG_REQ,
-     .help = N_("pool name or uuid")
-    },
+    VSH_VOLUME_POOL_REQ_OPT_COMMON,
     {.name = "file",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
@@ -558,10 +566,7 @@ static const vshCmdOptDef opts_vol_clone[] = {
      .flags = VSH_OFLAG_REQ,
      .help = N_("clone name")
     },
-    {.name = "pool",
-     .type = VSH_OT_STRING,
-     .help = N_("pool name or uuid")
-    },
+    VSH_VOLUME_POOL_STRING_OPT_COMMON,
     {.name = "prealloc-metadata",
      .type = VSH_OT_BOOL,
      .help = N_("preallocate metadata (for qcow2 instead of full allocation)")
@@ -661,10 +666,7 @@ static const vshCmdOptDef opts_vol_upload[] = {
      .flags = VSH_OFLAG_REQ,
      .help = N_("file")
     },
-    {.name = "pool",
-     .type = VSH_OT_STRING,
-     .help = N_("pool name or uuid")
-    },
+    VSH_VOLUME_POOL_STRING_OPT_COMMON,
     {.name = "offset",
      .type = VSH_OT_INT,
      .help = N_("volume offset to upload to")
@@ -775,10 +777,7 @@ static const vshCmdOptDef opts_vol_download[] = {
      .flags = VSH_OFLAG_REQ,
      .help = N_("file")
     },
-    {.name = "pool",
-     .type = VSH_OT_STRING,
-     .help = N_("pool name or uuid")
-    },
+    VSH_VOLUME_POOL_STRING_OPT_COMMON,
     {.name = "offset",
      .type = VSH_OT_INT,
      .help = N_("volume offset to download from")
@@ -883,10 +882,7 @@ static const vshCmdOptDef opts_vol_delete[] = {
      .flags = VSH_OFLAG_REQ,
      .help = N_("vol name, key or path")
     },
-    {.name = "pool",
-     .type = VSH_OT_STRING,
-     .help = N_("pool name or uuid")
-    },
+    VSH_VOLUME_POOL_STRING_OPT_COMMON,
     {.name = NULL}
 };
 
@@ -930,10 +926,7 @@ static const vshCmdOptDef opts_vol_wipe[] = {
      .flags = VSH_OFLAG_REQ,
      .help = N_("vol name, key or path")
     },
-    {.name = "pool",
-     .type = VSH_OT_STRING,
-     .help = N_("pool name or uuid")
-    },
+    VSH_VOLUME_POOL_STRING_OPT_COMMON,
     {.name = "algorithm",
      .type = VSH_OT_STRING,
      .help = N_("perform selected wiping algorithm")
@@ -1023,10 +1016,7 @@ static const vshCmdOptDef opts_vol_info[] = {
      .flags = VSH_OFLAG_REQ,
      .help = N_("vol name, key or path")
     },
-    {.name = "pool",
-     .type = VSH_OT_STRING,
-     .help = N_("pool name or uuid")
-    },
+    VSH_VOLUME_POOL_STRING_OPT_COMMON,
     {.name = NULL}
 };
 
@@ -1086,10 +1076,7 @@ static const vshCmdOptDef opts_vol_resize[] = {
      .flags = VSH_OFLAG_REQ,
      .help = N_("new capacity for the vol, as scaled integer (default bytes)")
     },
-    {.name = "pool",
-     .type = VSH_OT_STRING,
-     .help = N_("pool name or uuid")
-    },
+    VSH_VOLUME_POOL_STRING_OPT_COMMON,
     {.name = "allocate",
      .type = VSH_OT_BOOL,
      .help = N_("allocate the new capacity, rather than leaving it sparse")
@@ -1185,10 +1172,7 @@ static const vshCmdOptDef opts_vol_dumpxml[] = {
      .flags = VSH_OFLAG_REQ,
      .help = N_("vol name, key or path")
     },
-    {.name = "pool",
-     .type = VSH_OT_STRING,
-     .help = N_("pool name or uuid")
-    },
+    VSH_VOLUME_POOL_STRING_OPT_COMMON,
     {.name = NULL}
 };
 
@@ -1354,11 +1338,7 @@ static const vshCmdInfo info_vol_list[] = {
 };
 
 static const vshCmdOptDef opts_vol_list[] = {
-    {.name = "pool",
-     .type = VSH_OT_DATA,
-     .flags = VSH_OFLAG_REQ,
-     .help = N_("pool name or uuid")
-    },
+    VSH_VOLUME_POOL_REQ_OPT_COMMON,
     {.name = "details",
      .type = VSH_OT_BOOL,
      .help = N_("display extended details for volumes")
@@ -1700,10 +1680,7 @@ static const vshCmdOptDef opts_vol_key[] = {
      .flags = VSH_OFLAG_REQ,
      .help = N_("volume name or path")
     },
-    {.name = "pool",
-     .type = VSH_OT_STRING,
-     .help = N_("pool name or uuid")
-    },
+    VSH_VOLUME_POOL_STRING_OPT_COMMON,
     {.name = NULL}
 };
 
@@ -1739,10 +1716,7 @@ static const vshCmdOptDef opts_vol_path[] = {
      .flags = VSH_OFLAG_REQ,
      .help = N_("volume name or key")
     },
-    {.name = "pool",
-     .type = VSH_OT_STRING,
-     .help = N_("pool name or uuid")
-    },
+    VSH_VOLUME_POOL_STRING_OPT_COMMON,
     {.name = NULL}
 };
 
-- 
2.5.0

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to