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. Create 2 new macros for the create and string type options, but use the virsh.h common macro for the required for command option. Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx> --- tools/virsh-volume.c | 87 ++++++++++++++++------------------------------------ 1 file changed, 27 insertions(+), 60 deletions(-) diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 3408bee..cb350ee 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -42,6 +42,19 @@ #include "virxml.h" #include "virstring.h" +#define VIRSH_VOLUME_POOL_CREATE_OPT_COMMON \ + {.name = "pool", \ + .type = VSH_OT_DATA, \ + .flags = VSH_OFLAG_REQ, \ + .help = N_("pool name") \ + } \ + +#define VIRSH_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 +158,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") - }, + VIRSH_VOLUME_POOL_CREATE_OPT_COMMON, {.name = "name", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -353,11 +362,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") - }, + VIRSH_VOLUME_POOL_CREATE_OPT_COMMON, {.name = "file", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -423,11 +428,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") - }, + VIRSH_POOL_OPT_COMMON, {.name = "file", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -558,10 +559,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") - }, + VIRSH_VOLUME_POOL_STRING_OPT_COMMON, {.name = "prealloc-metadata", .type = VSH_OT_BOOL, .help = N_("preallocate metadata (for qcow2 instead of full allocation)") @@ -661,10 +659,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") - }, + VIRSH_VOLUME_POOL_STRING_OPT_COMMON, {.name = "offset", .type = VSH_OT_INT, .help = N_("volume offset to upload to") @@ -775,10 +770,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") - }, + VIRSH_VOLUME_POOL_STRING_OPT_COMMON, {.name = "offset", .type = VSH_OT_INT, .help = N_("volume offset to download from") @@ -883,10 +875,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") - }, + VIRSH_VOLUME_POOL_STRING_OPT_COMMON, {.name = NULL} }; @@ -930,10 +919,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") - }, + VIRSH_VOLUME_POOL_STRING_OPT_COMMON, {.name = "algorithm", .type = VSH_OT_STRING, .help = N_("perform selected wiping algorithm") @@ -1023,10 +1009,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") - }, + VIRSH_VOLUME_POOL_STRING_OPT_COMMON, {.name = NULL} }; @@ -1086,10 +1069,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") - }, + VIRSH_VOLUME_POOL_STRING_OPT_COMMON, {.name = "allocate", .type = VSH_OT_BOOL, .help = N_("allocate the new capacity, rather than leaving it sparse") @@ -1185,10 +1165,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") - }, + VIRSH_VOLUME_POOL_STRING_OPT_COMMON, {.name = NULL} }; @@ -1354,11 +1331,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") - }, + VIRSH_POOL_OPT_COMMON, {.name = "details", .type = VSH_OT_BOOL, .help = N_("display extended details for volumes") @@ -1700,10 +1673,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") - }, + VIRSH_VOLUME_POOL_STRING_OPT_COMMON, {.name = NULL} }; @@ -1739,10 +1709,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") - }, + VIRSH_VOLUME_POOL_STRING_OPT_COMMON, {.name = NULL} }; -- 2.5.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list