[libvirt] [PATCH 0/8] Use macros for more common virsh command options

As a follow on to a recent series which created macros for various virsh-*.c command options, see: http://www.redhat.com/archives/libvir-list/2015-December/msg00672.html (although best to view by index since there are varying opinions on the matter)... Modify virsh-domain.c and virsh-volume.c to "follow" the concept of macro-ifying some commonly used options. In order to choose, I used: $ grep "{.name =" tools/virsh-*.c | \ grep -v "help" | grep -v "desc" | grep -v NULL | \ sort -i | uniq -c | sort -n To generate a list by module. That generated a list where I randomly picked 9 as the nexus, leaving the following: 9 tools/virsh-domain.c: {.name = "persistent", 10 tools/virsh-snapshot.c: {.name = "domain", 12 tools/virsh-network.c: {.name = "network", 12 tools/virsh-pool.c: {.name = "pool", 13 tools/virsh-volume.c: {.name = "vol", 14 tools/virsh-domain.c: {.name = "file", 14 tools/virsh-domain-monitor.c: {.name = "domain", 14 tools/virsh-volume.c: {.name = "pool", 26 tools/virsh-domain.c: {.name = "current", 28 tools/virsh-domain.c: {.name = "config", 28 tools/virsh-domain.c: {.name = "live", 81 tools/virsh-domain.c: {.name = "domain", Because virsh-domain-monitor.c, virsh-network.c, and virsh-snapshot.c only had one element with larger counts - I just left them as is and focused on the virsh-domain.c and virsh-volume.c. The perhaps more controversial choice will be the "file" option in virsh-domain.c which had numerous different helpstr values. I chose to macro-ify them using the entire helpstr including the N_("xxx") rather than just "xxx" since the N_ is the I18N marker. John Ferlan (8): virsh: Create macro for common "domain" option virsh: Create macro for common "persistent" option virsh: Create macro for common "config" option virsh: Create macro for common "live" option virsh: Create macro for common "current" option virsh: Create macro for common "file" option virsh: Create macros for common "pool" options virsh: Create macros for common "vol" options tools/virsh-domain.c | 918 +++++++++++---------------------------------------- tools/virsh-volume.c | 155 +++------ 2 files changed, 247 insertions(+), 826 deletions(-) -- 2.5.0

Rather than continually cut-n-paste the strings into each command, create a common macro to be used generically. Note that not all '{.name = "domain",' entries are replaced, just those that have the common .help string of "domain name, id or uuid" and those that are required. Other instances won't take all 3 options, but some subset of those options as directed by the virshCommandOptDomainBy flags argument or in some instances where the domain is not a required option. Signed-off-by: John Ferlan <jferlan@redhat.com> --- tools/virsh-domain.c | 450 +++++++++------------------------------------------ 1 file changed, 80 insertions(+), 370 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 7650535..e766ec4 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -63,6 +63,12 @@ # define SA_SIGINFO 0 #endif +#define VSH_DOMAIN_OPT_COMMON \ + {.name = "domain", \ + .type = VSH_OT_DATA, \ + .flags = VSH_OFLAG_REQ, \ + .help = N_("domain name, id or uuid") \ + } \ static virDomainPtr virshLookupDomainInternal(vshControl *ctl, @@ -206,11 +212,7 @@ static const vshCmdInfo info_attach_device[] = { }; static const vshCmdOptDef opts_attach_device[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "file", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -308,11 +310,7 @@ static const vshCmdInfo info_attach_disk[] = { }; static const vshCmdOptDef opts_attach_disk[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "source", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ | VSH_OFLAG_EMPTY_OK, @@ -808,11 +806,7 @@ static const vshCmdInfo info_attach_interface[] = { }; static const vshCmdOptDef opts_attach_interface[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "type", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -1135,11 +1129,7 @@ static const vshCmdInfo info_autostart[] = { }; static const vshCmdOptDef opts_autostart[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "disable", .type = VSH_OT_BOOL, .help = N_("disable autostarting") @@ -1191,11 +1181,7 @@ static const vshCmdInfo info_blkdeviotune[] = { }; static const vshCmdOptDef opts_blkdeviotune[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "device", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -1534,11 +1520,7 @@ static const vshCmdInfo info_blkiotune[] = { }; static const vshCmdOptDef opts_blkiotune[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "weight", .type = VSH_OT_INT, .help = N_("IO Weight") @@ -2007,11 +1989,7 @@ static const vshCmdInfo info_block_commit[] = { }; static const vshCmdOptDef opts_block_commit[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "path", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -2227,11 +2205,7 @@ static const vshCmdInfo info_block_copy[] = { }; static const vshCmdOptDef opts_block_copy[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "path", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -2532,11 +2506,7 @@ static const vshCmdInfo info_block_job[] = { }; static const vshCmdOptDef opts_block_job[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "path", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -2777,11 +2747,7 @@ static const vshCmdInfo info_block_pull[] = { }; static const vshCmdOptDef opts_block_pull[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "path", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -2916,11 +2882,7 @@ static const vshCmdInfo info_block_resize[] = { }; static const vshCmdOptDef opts_block_resize[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "path", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -2984,11 +2946,7 @@ static const vshCmdInfo info_console[] = { }; static const vshCmdOptDef opts_console[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "devname", /* sc_prohibit_devname */ .type = VSH_OT_STRING, .help = N_("character device name") @@ -3082,11 +3040,7 @@ static const vshCmdInfo info_domif_setlink[] = { }; static const vshCmdOptDef opts_domif_setlink[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "interface", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -3269,11 +3223,7 @@ static const vshCmdInfo info_domiftune[] = { }; static const vshCmdOptDef opts_domiftune[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "interface", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -3479,11 +3429,7 @@ static const vshCmdInfo info_suspend[] = { }; static const vshCmdOptDef opts_suspend[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = NULL} }; @@ -3525,11 +3471,7 @@ static const vshCmdInfo info_dom_pm_suspend[] = { }; static const vshCmdOptDef opts_dom_pm_suspend[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "target", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -3607,11 +3549,7 @@ static const vshCmdInfo info_dom_pm_wakeup[] = { }; static const vshCmdOptDef opts_dom_pm_wakeup[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = NULL} }; @@ -4245,11 +4183,7 @@ static const vshCmdInfo info_save[] = { }; static const vshCmdOptDef opts_save[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "file", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -4715,11 +4649,7 @@ static const vshCmdInfo info_managedsave[] = { }; static const vshCmdOptDef opts_managedsave[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "bypass-cache", .type = VSH_OT_BOOL, .help = N_("avoid file system cache when saving") @@ -4839,11 +4769,7 @@ static const vshCmdInfo info_managedsaveremove[] = { }; static const vshCmdOptDef opts_managedsaveremove[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = NULL} }; @@ -4898,11 +4824,7 @@ static const vshCmdInfo info_schedinfo[] = { }; static const vshCmdOptDef opts_schedinfo[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "weight", .type = VSH_OT_INT, .flags = VSH_OFLAG_REQ_OPT, @@ -5226,11 +5148,7 @@ static const vshCmdInfo info_dump[] = { }; static const vshCmdOptDef opts_dump[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "file", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -5409,11 +5327,7 @@ static const vshCmdInfo info_screenshot[] = { }; static const vshCmdOptDef opts_screenshot[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "file", .type = VSH_OT_STRING, .help = N_("where to store the screenshot") @@ -5556,11 +5470,7 @@ static const vshCmdInfo info_set_user_password[] = { }; static const vshCmdOptDef opts_set_user_password[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "user", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -5624,11 +5534,7 @@ static const vshCmdInfo info_resume[] = { }; static const vshCmdOptDef opts_resume[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = NULL} }; @@ -5667,11 +5573,7 @@ static const vshCmdInfo info_shutdown[] = { }; static const vshCmdOptDef opts_shutdown[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "mode", .type = VSH_OT_STRING, .help = N_("shutdown mode: acpi|agent|initctl|signal|paravirt") @@ -5756,11 +5658,7 @@ static const vshCmdInfo info_reboot[] = { }; static const vshCmdOptDef opts_reboot[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "mode", .type = VSH_OT_STRING, .help = N_("shutdown mode: acpi|agent|initctl|signal|paravirt") @@ -5840,11 +5738,7 @@ static const vshCmdInfo info_reset[] = { }; static const vshCmdOptDef opts_reset[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = NULL} }; @@ -5883,11 +5777,7 @@ static const vshCmdInfo info_domjobinfo[] = { }; static const vshCmdOptDef opts_domjobinfo[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "completed", .type = VSH_OT_BOOL, .help = N_("return statistics of a recently completed job") @@ -6169,11 +6059,7 @@ static const vshCmdInfo info_domjobabort[] = { }; static const vshCmdOptDef opts_domjobabort[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = NULL} }; @@ -6207,11 +6093,7 @@ static const vshCmdInfo info_vcpucount[] = { }; static const vshCmdOptDef opts_vcpucount[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "maximum", .type = VSH_OT_BOOL, .help = N_("get maximum count of vcpus") @@ -6422,11 +6304,7 @@ static const vshCmdInfo info_vcpuinfo[] = { }; static const vshCmdOptDef opts_vcpuinfo[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "pretty", .type = VSH_OT_BOOL, .help = N_("return human readable output") @@ -6537,11 +6415,7 @@ static const vshCmdInfo info_vcpupin[] = { }; static const vshCmdOptDef opts_vcpupin[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "vcpu", .type = VSH_OT_INT, .help = N_("vcpu number") @@ -6749,11 +6623,7 @@ static const vshCmdInfo info_emulatorpin[] = { }; static const vshCmdOptDef opts_emulatorpin[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "cpulist", .type = VSH_OT_STRING, .flags = VSH_OFLAG_EMPTY_OK, @@ -6866,11 +6736,7 @@ static const vshCmdInfo info_setvcpus[] = { }; static const vshCmdOptDef opts_setvcpus[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "count", .type = VSH_OT_INT, .flags = VSH_OFLAG_REQ, @@ -6967,11 +6833,7 @@ static const vshCmdInfo info_iothreadinfo[] = { {.name = NULL} }; static const vshCmdOptDef opts_iothreadinfo[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "config", .type = VSH_OT_BOOL, .help = N_("affect next boot") @@ -7056,11 +6918,7 @@ static const vshCmdInfo info_iothreadpin[] = { }; static const vshCmdOptDef opts_iothreadpin[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "iothread", .type = VSH_OT_INT, .flags = VSH_OFLAG_REQ, @@ -7151,11 +7009,7 @@ static const vshCmdInfo info_iothreadadd[] = { }; static const vshCmdOptDef opts_iothreadadd[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "id", .type = VSH_OT_INT, .flags = VSH_OFLAG_REQ, @@ -7229,11 +7083,7 @@ static const vshCmdInfo info_iothreaddel[] = { }; static const vshCmdOptDef opts_iothreaddel[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "id", .type = VSH_OT_INT, .flags = VSH_OFLAG_REQ, @@ -7526,11 +7376,7 @@ static const vshCmdInfo info_cpu_stats[] = { }; static const vshCmdOptDef opts_cpu_stats[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "total", .type = VSH_OT_BOOL, .help = N_("Show total statistics only") @@ -7877,11 +7723,7 @@ static const vshCmdInfo info_destroy[] = { }; static const vshCmdOptDef opts_destroy[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "graceful", .type = VSH_OT_BOOL, .help = N_("terminate gracefully") @@ -7934,11 +7776,7 @@ static const vshCmdInfo info_desc[] = { }; static const vshCmdOptDef opts_desc[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "live", .type = VSH_OT_BOOL, .help = N_("modify/get running state") @@ -8113,11 +7951,7 @@ static const vshCmdInfo info_metadata[] = { }; static const vshCmdOptDef opts_metadata[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "uri", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -8272,11 +8106,7 @@ static const vshCmdInfo info_inject_nmi[] = { }; static const vshCmdOptDef opts_inject_nmi[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = NULL} }; @@ -8310,11 +8140,7 @@ static const vshCmdInfo info_send_key[] = { }; static const vshCmdOptDef opts_send_key[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "codeset", .type = VSH_OT_STRING, .flags = VSH_OFLAG_REQ_OPT, @@ -8410,11 +8236,7 @@ static const vshCmdInfo info_send_process_signal[] = { }; static const vshCmdOptDef opts_send_process_signal[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "pid", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -8519,11 +8341,7 @@ static const vshCmdInfo info_setmem[] = { }; static const vshCmdOptDef opts_setmem[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "kilobytes", .type = VSH_OT_ALIAS, .help = "size" @@ -8613,11 +8431,7 @@ static const vshCmdInfo info_setmaxmem[] = { }; static const vshCmdOptDef opts_setmaxmem[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "kilobytes", .type = VSH_OT_ALIAS, .help = "size" @@ -8714,11 +8528,7 @@ static const vshCmdInfo info_memtune[] = { }; static const vshCmdOptDef opts_memtune[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "hard-limit", .type = VSH_OT_INT, .help = N_("Max memory, as scaled integer (default KiB)") @@ -8904,11 +8714,7 @@ static const vshCmdInfo info_numatune[] = { }; static const vshCmdOptDef opts_numatune[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "mode", .type = VSH_OT_STRING, .help = N_("NUMA mode, one of strict, preferred and interleave \n" @@ -9052,11 +8858,7 @@ static const vshCmdInfo info_qemu_monitor_command[] = { }; static const vshCmdOptDef opts_qemu_monitor_command[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "hmp", .type = VSH_OT_BOOL, .help = N_("command is in human monitor protocol") @@ -9342,11 +9144,7 @@ static const vshCmdInfo info_qemu_agent_command[] = { }; static const vshCmdOptDef opts_qemu_agent_command[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "timeout", .type = VSH_OT_INT, .flags = VSH_OFLAG_REQ_OPT, @@ -9469,11 +9267,7 @@ static const vshCmdInfo info_lxc_enter_namespace[] = { }; static const vshCmdOptDef opts_lxc_enter_namespace[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "noseclabel", .type = VSH_OT_BOOL, .help = N_("Do not change process security label") @@ -9612,11 +9406,7 @@ static const vshCmdInfo info_dumpxml[] = { }; static const vshCmdOptDef opts_dumpxml[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "inactive", .type = VSH_OT_BOOL, .help = N_("show inactive defined XML") @@ -9836,11 +9626,7 @@ static const vshCmdInfo info_domrename[] = { }; static const vshCmdOptDef opts_domrename[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "new-name", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -9969,11 +9755,7 @@ static const vshCmdInfo info_migrate[] = { }; static const vshCmdOptDef opts_migrate[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "desturi", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -10339,11 +10121,7 @@ static const vshCmdInfo info_migrate_setmaxdowntime[] = { }; static const vshCmdOptDef opts_migrate_setmaxdowntime[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "downtime", .type = VSH_OT_INT, .flags = VSH_OFLAG_REQ, @@ -10394,11 +10172,7 @@ static const vshCmdInfo info_migrate_compcache[] = { }; static const vshCmdOptDef opts_migrate_compcache[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "size", .type = VSH_OT_INT, .flags = VSH_OFLAG_REQ_OPT, @@ -10455,11 +10229,7 @@ static const vshCmdInfo info_migrate_setspeed[] = { }; static const vshCmdOptDef opts_migrate_setspeed[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "bandwidth", .type = VSH_OT_INT, .flags = VSH_OFLAG_REQ, @@ -10505,11 +10275,7 @@ static const vshCmdInfo info_migrate_getspeed[] = { }; static const vshCmdOptDef opts_migrate_getspeed[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = NULL} }; @@ -10550,11 +10316,7 @@ static const vshCmdInfo info_domdisplay[] = { }; static const vshCmdOptDef opts_domdisplay[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "include-password", .type = VSH_OT_BOOL, .help = N_("includes the password into the connection URI if available") @@ -10773,11 +10535,7 @@ static const vshCmdInfo info_vncdisplay[] = { }; static const vshCmdOptDef opts_vncdisplay[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = NULL} }; @@ -10858,11 +10616,7 @@ static const vshCmdInfo info_ttyconsole[] = { }; static const vshCmdOptDef opts_ttyconsole[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = NULL} }; @@ -10918,11 +10672,7 @@ static const vshCmdInfo info_domhostname[] = { }; static const vshCmdOptDef opts_domhostname[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = NULL} }; @@ -11081,11 +10831,7 @@ static const vshCmdInfo info_detach_device[] = { }; static const vshCmdOptDef opts_detach_device[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "file", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -11182,11 +10928,7 @@ static const vshCmdInfo info_update_device[] = { }; static const vshCmdOptDef opts_update_device[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "file", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -11284,11 +11026,7 @@ static const vshCmdInfo info_detach_interface[] = { }; static const vshCmdOptDef opts_detach_interface[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "type", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -11704,11 +11442,7 @@ static const vshCmdInfo info_detach_disk[] = { }; static const vshCmdOptDef opts_detach_disk[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "target", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -11820,11 +11554,7 @@ static const vshCmdInfo info_edit[] = { }; static const vshCmdOptDef opts_edit[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "skip-validate", .type = VSH_OT_BOOL, .help = N_("skip validation of the XML against the schema") @@ -12671,11 +12401,7 @@ static const vshCmdInfo info_change_media[] = { }; static const vshCmdOptDef opts_change_media[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "path", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -12843,11 +12569,7 @@ static const vshCmdInfo info_domfstrim[] = { }; static const vshCmdOptDef opts_domfstrim[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "minimum", .type = VSH_OT_INT, .help = N_("Just a hint to ignore contiguous " @@ -12900,11 +12622,7 @@ static const vshCmdInfo info_domfsfreeze[] = { }; static const vshCmdOptDef opts_domfsfreeze[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "mountpoint", .type = VSH_OT_ARGV, .help = N_("mountpoint path to be frozen") @@ -12957,11 +12675,7 @@ static const vshCmdInfo info_domfsthaw[] = { }; static const vshCmdOptDef opts_domfsthaw[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = "mountpoint", .type = VSH_OT_ARGV, .help = N_("mountpoint path to be thawed") @@ -13014,11 +12728,7 @@ static const vshCmdInfo info_domfsinfo[] = { }; static const vshCmdOptDef opts_domfsinfo[] = { - {.name = "domain", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("domain name, id or uuid") - }, + VSH_DOMAIN_OPT_COMMON, {.name = NULL} }; -- 2.5.0

On 17/12/15 17:55, John Ferlan wrote:
Rather than continually cut-n-paste the strings into each command, create a common macro to be used generically. Note that not all '{.name = "domain",' entries are replaced, just those that have the common .help string of "domain name, id or uuid" and those that are required.
Other instances won't take all 3 options, but some subset of those options as directed by the virshCommandOptDomainBy flags argument or in some instances where the domain is not a required option.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- tools/virsh-domain.c | 450 +++++++++------------------------------------------ 1 file changed, 80 insertions(+), 370 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 7650535..e766ec4 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -63,6 +63,12 @@ # define SA_SIGINFO 0 #endif
+#define VSH_DOMAIN_OPT_COMMON \ + {.name = "domain", \ + .type = VSH_OT_DATA, \ + .flags = VSH_OFLAG_REQ, \ + .help = N_("domain name, id or uuid") \ + } \
Since generic 'vsh.c' module introduction in commit 834c5720, we prefix macros/constants/methods with VIRSH/virsh within all virsh modules. Erik

On 12/18/2015 03:31 AM, Erik Skultety wrote:
On 17/12/15 17:55, John Ferlan wrote:
Rather than continually cut-n-paste the strings into each command, create a common macro to be used generically. Note that not all '{.name = "domain",' entries are replaced, just those that have the common .help string of "domain name, id or uuid" and those that are required.
Other instances won't take all 3 options, but some subset of those options as directed by the virshCommandOptDomainBy flags argument or in some instances where the domain is not a required option.
Signed-off-by: John Ferlan <jferlan@redhat.com> --- tools/virsh-domain.c | 450 +++++++++------------------------------------------ 1 file changed, 80 insertions(+), 370 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 7650535..e766ec4 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -63,6 +63,12 @@ # define SA_SIGINFO 0 #endif
+#define VSH_DOMAIN_OPT_COMMON \ + {.name = "domain", \ + .type = VSH_OT_DATA, \ + .flags = VSH_OFLAG_REQ, \ + .help = N_("domain name, id or uuid") \ + } \
Since generic 'vsh.c' module introduction in commit 834c5720, we prefix macros/constants/methods with VIRSH/virsh within all virsh modules.
OK - not a problem to change/convert... I'll have to also do the same for virsh-pool.c too. I use the VSH_ prefix on advice from review of that series: http://www.redhat.com/archives/libvir-list/2015-December/msg00675.html John

Rather than continually cut-n-paste the strings into each command, create a common macro to be used generically. Note that not all '{.name = "persistent",' entries are replaced, just those that have the common .help string of "make live change persistent". Non replaced instances are unique to the command. Signed-off-by: John Ferlan <jferlan@redhat.com> --- tools/virsh-domain.c | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index e766ec4..094cccf 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -70,6 +70,12 @@ .help = N_("domain name, id or uuid") \ } \ +#define VSH_DOMAIN_PERSISTENT_OPT_COMMON \ + {.name = "persistent", \ + .type = VSH_OT_BOOL, \ + .help = N_("make live change persistent") \ + } \ + static virDomainPtr virshLookupDomainInternal(vshControl *ctl, const char *cmdname, @@ -218,10 +224,7 @@ static const vshCmdOptDef opts_attach_device[] = { .flags = VSH_OFLAG_REQ, .help = N_("XML file") }, - {.name = "persistent", - .type = VSH_OT_BOOL, - .help = N_("make live change persistent") - }, + VSH_DOMAIN_PERSISTENT_OPT_COMMON, {.name = "config", .type = VSH_OT_BOOL, .help = N_("affect next boot") @@ -381,10 +384,7 @@ static const vshCmdOptDef opts_attach_disk[] = { .type = VSH_OT_BOOL, .help = N_("print XML document rather than attach the disk") }, - {.name = "persistent", - .type = VSH_OT_BOOL, - .help = N_("make live change persistent") - }, + VSH_DOMAIN_PERSISTENT_OPT_COMMON, {.name = "config", .type = VSH_OT_BOOL, .help = N_("affect next boot") @@ -841,10 +841,7 @@ static const vshCmdOptDef opts_attach_interface[] = { .type = VSH_OT_STRING, .help = N_("control domain's outgoing traffics") }, - {.name = "persistent", - .type = VSH_OT_BOOL, - .help = N_("make live change persistent") - }, + VSH_DOMAIN_PERSISTENT_OPT_COMMON, {.name = "config", .type = VSH_OT_BOOL, .help = N_("affect next boot") @@ -10837,10 +10834,7 @@ static const vshCmdOptDef opts_detach_device[] = { .flags = VSH_OFLAG_REQ, .help = N_("XML file") }, - {.name = "persistent", - .type = VSH_OT_BOOL, - .help = N_("make live change persistent") - }, + VSH_DOMAIN_PERSISTENT_OPT_COMMON, {.name = "config", .type = VSH_OT_BOOL, .help = N_("affect next boot") @@ -10934,10 +10928,7 @@ static const vshCmdOptDef opts_update_device[] = { .flags = VSH_OFLAG_REQ, .help = N_("XML file") }, - {.name = "persistent", - .type = VSH_OT_BOOL, - .help = N_("make live change persistent") - }, + VSH_DOMAIN_PERSISTENT_OPT_COMMON, {.name = "config", .type = VSH_OT_BOOL, .help = N_("affect next boot") @@ -11036,10 +11027,7 @@ static const vshCmdOptDef opts_detach_interface[] = { .type = VSH_OT_STRING, .help = N_("MAC address") }, - {.name = "persistent", - .type = VSH_OT_BOOL, - .help = N_("make live change persistent") - }, + VSH_DOMAIN_PERSISTENT_OPT_COMMON, {.name = "config", .type = VSH_OT_BOOL, .help = N_("affect next boot") @@ -11448,10 +11436,7 @@ static const vshCmdOptDef opts_detach_disk[] = { .flags = VSH_OFLAG_REQ, .help = N_("target of disk device") }, - {.name = "persistent", - .type = VSH_OT_BOOL, - .help = N_("make live change persistent") - }, + VSH_DOMAIN_PERSISTENT_OPT_COMMON, {.name = "config", .type = VSH_OT_BOOL, .help = N_("affect next boot") -- 2.5.0

Rather than continually cut-n-paste the strings into each command, create a common macro to be used generically. Note that not all '{.name = "config",' entries are replaced, just those that have the common .help string of "affect next boot". Non replaced instances are unique to the command. Signed-off-by: John Ferlan <jferlan@redhat.com> --- tools/virsh-domain.c | 116 +++++++++++++-------------------------------------- 1 file changed, 28 insertions(+), 88 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 094cccf..6a34688 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -76,6 +76,12 @@ .help = N_("make live change persistent") \ } \ +#define VSH_DOMAIN_CONFIG_OPT_COMMON \ + {.name = "config", \ + .type = VSH_OT_BOOL, \ + .help = N_("affect next boot") \ + } \ + static virDomainPtr virshLookupDomainInternal(vshControl *ctl, const char *cmdname, @@ -225,10 +231,7 @@ static const vshCmdOptDef opts_attach_device[] = { .help = N_("XML file") }, VSH_DOMAIN_PERSISTENT_OPT_COMMON, - {.name = "config", - .type = VSH_OT_BOOL, - .help = N_("affect next boot") - }, + VSH_DOMAIN_CONFIG_OPT_COMMON, {.name = "live", .type = VSH_OT_BOOL, .help = N_("affect running domain") @@ -385,10 +388,7 @@ static const vshCmdOptDef opts_attach_disk[] = { .help = N_("print XML document rather than attach the disk") }, VSH_DOMAIN_PERSISTENT_OPT_COMMON, - {.name = "config", - .type = VSH_OT_BOOL, - .help = N_("affect next boot") - }, + VSH_DOMAIN_CONFIG_OPT_COMMON, {.name = "live", .type = VSH_OT_BOOL, .help = N_("affect running domain") @@ -842,10 +842,7 @@ static const vshCmdOptDef opts_attach_interface[] = { .help = N_("control domain's outgoing traffics") }, VSH_DOMAIN_PERSISTENT_OPT_COMMON, - {.name = "config", - .type = VSH_OT_BOOL, - .help = N_("affect next boot") - }, + VSH_DOMAIN_CONFIG_OPT_COMMON, {.name = "live", .type = VSH_OT_BOOL, .help = N_("affect running domain") @@ -1288,10 +1285,7 @@ static const vshCmdOptDef opts_blkdeviotune[] = { .type = VSH_OT_INT, .help = N_("I/O size in bytes") }, - {.name = "config", - .type = VSH_OT_BOOL, - .help = N_("affect next boot") - }, + VSH_DOMAIN_CONFIG_OPT_COMMON, {.name = "live", .type = VSH_OT_BOOL, .help = N_("affect running domain") @@ -1542,10 +1536,7 @@ static const vshCmdOptDef opts_blkiotune[] = { .type = VSH_OT_STRING, .help = N_("per-device bytes wrote per second, in the form of /path/to/device,write_bytes_sec,...") }, - {.name = "config", - .type = VSH_OT_BOOL, - .help = N_("affect next boot") - }, + VSH_DOMAIN_CONFIG_OPT_COMMON, {.name = "live", .type = VSH_OT_BOOL, .help = N_("affect running domain") @@ -3052,10 +3043,7 @@ static const vshCmdOptDef opts_domif_setlink[] = { .type = VSH_OT_ALIAS, .help = "config" }, - {.name = "config", - .type = VSH_OT_BOOL, - .help = N_("affect next boot") - }, + VSH_DOMAIN_CONFIG_OPT_COMMON, {.name = NULL} }; @@ -3234,10 +3222,7 @@ static const vshCmdOptDef opts_domiftune[] = { .type = VSH_OT_STRING, .help = N_("control domain's outgoing traffics") }, - {.name = "config", - .type = VSH_OT_BOOL, - .help = N_("affect next boot") - }, + VSH_DOMAIN_CONFIG_OPT_COMMON, {.name = "live", .type = VSH_OT_BOOL, .help = N_("affect running domain") @@ -6422,10 +6407,7 @@ static const vshCmdOptDef opts_vcpupin[] = { .flags = VSH_OFLAG_EMPTY_OK, .help = N_("host cpu number(s) to set, or omit option to query") }, - {.name = "config", - .type = VSH_OT_BOOL, - .help = N_("affect next boot") - }, + VSH_DOMAIN_CONFIG_OPT_COMMON, {.name = "live", .type = VSH_OT_BOOL, .help = N_("affect running domain") @@ -6626,10 +6608,7 @@ static const vshCmdOptDef opts_emulatorpin[] = { .flags = VSH_OFLAG_EMPTY_OK, .help = N_("host cpu number(s) to set, or omit option to query") }, - {.name = "config", - .type = VSH_OT_BOOL, - .help = N_("affect next boot") - }, + VSH_DOMAIN_CONFIG_OPT_COMMON, {.name = "live", .type = VSH_OT_BOOL, .help = N_("affect running domain") @@ -6743,10 +6722,7 @@ static const vshCmdOptDef opts_setvcpus[] = { .type = VSH_OT_BOOL, .help = N_("set maximum limit on next boot") }, - {.name = "config", - .type = VSH_OT_BOOL, - .help = N_("affect next boot") - }, + VSH_DOMAIN_CONFIG_OPT_COMMON, {.name = "live", .type = VSH_OT_BOOL, .help = N_("affect running domain") @@ -6831,10 +6807,7 @@ static const vshCmdInfo info_iothreadinfo[] = { }; static const vshCmdOptDef opts_iothreadinfo[] = { VSH_DOMAIN_OPT_COMMON, - {.name = "config", - .type = VSH_OT_BOOL, - .help = N_("affect next boot") - }, + VSH_DOMAIN_CONFIG_OPT_COMMON, {.name = "live", .type = VSH_OT_BOOL, .help = N_("affect running domain") @@ -6926,10 +6899,7 @@ static const vshCmdOptDef opts_iothreadpin[] = { .flags = VSH_OFLAG_REQ, .help = N_("host cpu number(s) to set") }, - {.name = "config", - .type = VSH_OT_BOOL, - .help = N_("affect next boot") - }, + VSH_DOMAIN_CONFIG_OPT_COMMON, {.name = "live", .type = VSH_OT_BOOL, .help = N_("affect running domain") @@ -7012,10 +6982,7 @@ static const vshCmdOptDef opts_iothreadadd[] = { .flags = VSH_OFLAG_REQ, .help = N_("iothread for the new IOThread") }, - {.name = "config", - .type = VSH_OT_BOOL, - .help = N_("affect next boot") - }, + VSH_DOMAIN_CONFIG_OPT_COMMON, {.name = "live", .type = VSH_OT_BOOL, .help = N_("affect running domain") @@ -7086,10 +7053,7 @@ static const vshCmdOptDef opts_iothreaddel[] = { .flags = VSH_OFLAG_REQ, .help = N_("iothread_id for the IOThread to delete") }, - {.name = "config", - .type = VSH_OT_BOOL, - .help = N_("affect next boot") - }, + VSH_DOMAIN_CONFIG_OPT_COMMON, {.name = "live", .type = VSH_OT_BOOL, .help = N_("affect running domain") @@ -8348,10 +8312,7 @@ static const vshCmdOptDef opts_setmem[] = { .flags = VSH_OFLAG_REQ, .help = N_("new memory size, as scaled integer (default KiB)") }, - {.name = "config", - .type = VSH_OT_BOOL, - .help = N_("affect next boot") - }, + VSH_DOMAIN_CONFIG_OPT_COMMON, {.name = "live", .type = VSH_OT_BOOL, .help = N_("affect running domain") @@ -8438,10 +8399,7 @@ static const vshCmdOptDef opts_setmaxmem[] = { .flags = VSH_OFLAG_REQ, .help = N_("new maximum memory size, as scaled integer (default KiB)") }, - {.name = "config", - .type = VSH_OT_BOOL, - .help = N_("affect next boot") - }, + VSH_DOMAIN_CONFIG_OPT_COMMON, {.name = "live", .type = VSH_OT_BOOL, .help = N_("affect running domain") @@ -8542,10 +8500,7 @@ static const vshCmdOptDef opts_memtune[] = { .type = VSH_OT_INT, .help = N_("Min guaranteed memory, as scaled integer (default KiB)") }, - {.name = "config", - .type = VSH_OT_BOOL, - .help = N_("affect next boot") - }, + VSH_DOMAIN_CONFIG_OPT_COMMON, {.name = "live", .type = VSH_OT_BOOL, .help = N_("affect running domain") @@ -8721,10 +8676,7 @@ static const vshCmdOptDef opts_numatune[] = { .type = VSH_OT_STRING, .help = N_("NUMA node selections to set") }, - {.name = "config", - .type = VSH_OT_BOOL, - .help = N_("affect next boot") - }, + VSH_DOMAIN_CONFIG_OPT_COMMON, {.name = "live", .type = VSH_OT_BOOL, .help = N_("affect running domain") @@ -10835,10 +10787,7 @@ static const vshCmdOptDef opts_detach_device[] = { .help = N_("XML file") }, VSH_DOMAIN_PERSISTENT_OPT_COMMON, - {.name = "config", - .type = VSH_OT_BOOL, - .help = N_("affect next boot") - }, + VSH_DOMAIN_CONFIG_OPT_COMMON, {.name = "live", .type = VSH_OT_BOOL, .help = N_("affect running domain") @@ -10929,10 +10878,7 @@ static const vshCmdOptDef opts_update_device[] = { .help = N_("XML file") }, VSH_DOMAIN_PERSISTENT_OPT_COMMON, - {.name = "config", - .type = VSH_OT_BOOL, - .help = N_("affect next boot") - }, + VSH_DOMAIN_CONFIG_OPT_COMMON, {.name = "live", .type = VSH_OT_BOOL, .help = N_("affect running domain") @@ -11028,10 +10974,7 @@ static const vshCmdOptDef opts_detach_interface[] = { .help = N_("MAC address") }, VSH_DOMAIN_PERSISTENT_OPT_COMMON, - {.name = "config", - .type = VSH_OT_BOOL, - .help = N_("affect next boot") - }, + VSH_DOMAIN_CONFIG_OPT_COMMON, {.name = "live", .type = VSH_OT_BOOL, .help = N_("affect running domain") @@ -11437,10 +11380,7 @@ static const vshCmdOptDef opts_detach_disk[] = { .help = N_("target of disk device") }, VSH_DOMAIN_PERSISTENT_OPT_COMMON, - {.name = "config", - .type = VSH_OT_BOOL, - .help = N_("affect next boot") - }, + VSH_DOMAIN_CONFIG_OPT_COMMON, {.name = "live", .type = VSH_OT_BOOL, .help = N_("affect running domain") -- 2.5.0

Rather than continually cut-n-paste the strings into each command, create a common macro to be used generically. Note that not all '{.name = "live",' entries are replaced, just those that have the common .help string of "affect running domain". Non replaced instances are unique to the command. Signed-off-by: John Ferlan <jferlan@redhat.com> --- tools/virsh-domain.c | 111 +++++++++++++-------------------------------------- 1 file changed, 27 insertions(+), 84 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 6a34688..c9e8475 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -82,6 +82,12 @@ .help = N_("affect next boot") \ } \ +#define VSH_DOMAIN_LIVE_OPT_COMMON \ + {.name = "live", \ + .type = VSH_OT_BOOL, \ + .help = N_("affect running domain") \ + } \ + static virDomainPtr virshLookupDomainInternal(vshControl *ctl, const char *cmdname, @@ -232,10 +238,7 @@ static const vshCmdOptDef opts_attach_device[] = { }, VSH_DOMAIN_PERSISTENT_OPT_COMMON, VSH_DOMAIN_CONFIG_OPT_COMMON, - {.name = "live", - .type = VSH_OT_BOOL, - .help = N_("affect running domain") - }, + VSH_DOMAIN_LIVE_OPT_COMMON, {.name = "current", .type = VSH_OT_BOOL, .help = N_("affect current domain") @@ -389,10 +392,7 @@ static const vshCmdOptDef opts_attach_disk[] = { }, VSH_DOMAIN_PERSISTENT_OPT_COMMON, VSH_DOMAIN_CONFIG_OPT_COMMON, - {.name = "live", - .type = VSH_OT_BOOL, - .help = N_("affect running domain") - }, + VSH_DOMAIN_LIVE_OPT_COMMON, {.name = "current", .type = VSH_OT_BOOL, .help = N_("affect current domain") @@ -843,10 +843,7 @@ static const vshCmdOptDef opts_attach_interface[] = { }, VSH_DOMAIN_PERSISTENT_OPT_COMMON, VSH_DOMAIN_CONFIG_OPT_COMMON, - {.name = "live", - .type = VSH_OT_BOOL, - .help = N_("affect running domain") - }, + VSH_DOMAIN_LIVE_OPT_COMMON, {.name = "current", .type = VSH_OT_BOOL, .help = N_("affect current domain") @@ -1286,10 +1283,7 @@ static const vshCmdOptDef opts_blkdeviotune[] = { .help = N_("I/O size in bytes") }, VSH_DOMAIN_CONFIG_OPT_COMMON, - {.name = "live", - .type = VSH_OT_BOOL, - .help = N_("affect running domain") - }, + VSH_DOMAIN_LIVE_OPT_COMMON, {.name = "current", .type = VSH_OT_BOOL, .help = N_("affect current domain") @@ -1537,10 +1531,7 @@ static const vshCmdOptDef opts_blkiotune[] = { .help = N_("per-device bytes wrote per second, in the form of /path/to/device,write_bytes_sec,...") }, VSH_DOMAIN_CONFIG_OPT_COMMON, - {.name = "live", - .type = VSH_OT_BOOL, - .help = N_("affect running domain") - }, + VSH_DOMAIN_LIVE_OPT_COMMON, {.name = "current", .type = VSH_OT_BOOL, .help = N_("affect current domain") @@ -3223,10 +3214,7 @@ static const vshCmdOptDef opts_domiftune[] = { .help = N_("control domain's outgoing traffics") }, VSH_DOMAIN_CONFIG_OPT_COMMON, - {.name = "live", - .type = VSH_OT_BOOL, - .help = N_("affect running domain") - }, + VSH_DOMAIN_LIVE_OPT_COMMON, {.name = "current", .type = VSH_OT_BOOL, .help = N_("affect current domain") @@ -6408,10 +6396,7 @@ static const vshCmdOptDef opts_vcpupin[] = { .help = N_("host cpu number(s) to set, or omit option to query") }, VSH_DOMAIN_CONFIG_OPT_COMMON, - {.name = "live", - .type = VSH_OT_BOOL, - .help = N_("affect running domain") - }, + VSH_DOMAIN_LIVE_OPT_COMMON, {.name = "current", .type = VSH_OT_BOOL, .help = N_("affect current domain") @@ -6609,10 +6594,7 @@ static const vshCmdOptDef opts_emulatorpin[] = { .help = N_("host cpu number(s) to set, or omit option to query") }, VSH_DOMAIN_CONFIG_OPT_COMMON, - {.name = "live", - .type = VSH_OT_BOOL, - .help = N_("affect running domain") - }, + VSH_DOMAIN_LIVE_OPT_COMMON, {.name = "current", .type = VSH_OT_BOOL, .help = N_("affect current domain") @@ -6723,10 +6705,7 @@ static const vshCmdOptDef opts_setvcpus[] = { .help = N_("set maximum limit on next boot") }, VSH_DOMAIN_CONFIG_OPT_COMMON, - {.name = "live", - .type = VSH_OT_BOOL, - .help = N_("affect running domain") - }, + VSH_DOMAIN_LIVE_OPT_COMMON, {.name = "current", .type = VSH_OT_BOOL, .help = N_("affect current domain") @@ -6808,10 +6787,7 @@ static const vshCmdInfo info_iothreadinfo[] = { static const vshCmdOptDef opts_iothreadinfo[] = { VSH_DOMAIN_OPT_COMMON, VSH_DOMAIN_CONFIG_OPT_COMMON, - {.name = "live", - .type = VSH_OT_BOOL, - .help = N_("affect running domain") - }, + VSH_DOMAIN_LIVE_OPT_COMMON, {.name = "current", .type = VSH_OT_BOOL, .help = N_("affect current domain") @@ -6900,10 +6876,7 @@ static const vshCmdOptDef opts_iothreadpin[] = { .help = N_("host cpu number(s) to set") }, VSH_DOMAIN_CONFIG_OPT_COMMON, - {.name = "live", - .type = VSH_OT_BOOL, - .help = N_("affect running domain") - }, + VSH_DOMAIN_LIVE_OPT_COMMON, {.name = "current", .type = VSH_OT_BOOL, .help = N_("affect current domain") @@ -6983,10 +6956,7 @@ static const vshCmdOptDef opts_iothreadadd[] = { .help = N_("iothread for the new IOThread") }, VSH_DOMAIN_CONFIG_OPT_COMMON, - {.name = "live", - .type = VSH_OT_BOOL, - .help = N_("affect running domain") - }, + VSH_DOMAIN_LIVE_OPT_COMMON, {.name = "current", .type = VSH_OT_BOOL, .help = N_("affect current domain") @@ -7054,10 +7024,7 @@ static const vshCmdOptDef opts_iothreaddel[] = { .help = N_("iothread_id for the IOThread to delete") }, VSH_DOMAIN_CONFIG_OPT_COMMON, - {.name = "live", - .type = VSH_OT_BOOL, - .help = N_("affect running domain") - }, + VSH_DOMAIN_LIVE_OPT_COMMON, {.name = "current", .type = VSH_OT_BOOL, .help = N_("affect current domain") @@ -8313,10 +8280,7 @@ static const vshCmdOptDef opts_setmem[] = { .help = N_("new memory size, as scaled integer (default KiB)") }, VSH_DOMAIN_CONFIG_OPT_COMMON, - {.name = "live", - .type = VSH_OT_BOOL, - .help = N_("affect running domain") - }, + VSH_DOMAIN_LIVE_OPT_COMMON, {.name = "current", .type = VSH_OT_BOOL, .help = N_("affect current domain") @@ -8400,10 +8364,7 @@ static const vshCmdOptDef opts_setmaxmem[] = { .help = N_("new maximum memory size, as scaled integer (default KiB)") }, VSH_DOMAIN_CONFIG_OPT_COMMON, - {.name = "live", - .type = VSH_OT_BOOL, - .help = N_("affect running domain") - }, + VSH_DOMAIN_LIVE_OPT_COMMON, {.name = "current", .type = VSH_OT_BOOL, .help = N_("affect current domain") @@ -8501,10 +8462,7 @@ static const vshCmdOptDef opts_memtune[] = { .help = N_("Min guaranteed memory, as scaled integer (default KiB)") }, VSH_DOMAIN_CONFIG_OPT_COMMON, - {.name = "live", - .type = VSH_OT_BOOL, - .help = N_("affect running domain") - }, + VSH_DOMAIN_LIVE_OPT_COMMON, {.name = "current", .type = VSH_OT_BOOL, .help = N_("affect current domain") @@ -8677,10 +8635,7 @@ static const vshCmdOptDef opts_numatune[] = { .help = N_("NUMA node selections to set") }, VSH_DOMAIN_CONFIG_OPT_COMMON, - {.name = "live", - .type = VSH_OT_BOOL, - .help = N_("affect running domain") - }, + VSH_DOMAIN_LIVE_OPT_COMMON, {.name = "current", .type = VSH_OT_BOOL, .help = N_("affect current domain") @@ -10788,10 +10743,7 @@ static const vshCmdOptDef opts_detach_device[] = { }, VSH_DOMAIN_PERSISTENT_OPT_COMMON, VSH_DOMAIN_CONFIG_OPT_COMMON, - {.name = "live", - .type = VSH_OT_BOOL, - .help = N_("affect running domain") - }, + VSH_DOMAIN_LIVE_OPT_COMMON, {.name = "current", .type = VSH_OT_BOOL, .help = N_("affect current domain") @@ -10879,10 +10831,7 @@ static const vshCmdOptDef opts_update_device[] = { }, VSH_DOMAIN_PERSISTENT_OPT_COMMON, VSH_DOMAIN_CONFIG_OPT_COMMON, - {.name = "live", - .type = VSH_OT_BOOL, - .help = N_("affect running domain") - }, + VSH_DOMAIN_LIVE_OPT_COMMON, {.name = "current", .type = VSH_OT_BOOL, .help = N_("affect current domain") @@ -10975,10 +10924,7 @@ static const vshCmdOptDef opts_detach_interface[] = { }, VSH_DOMAIN_PERSISTENT_OPT_COMMON, VSH_DOMAIN_CONFIG_OPT_COMMON, - {.name = "live", - .type = VSH_OT_BOOL, - .help = N_("affect running domain") - }, + VSH_DOMAIN_LIVE_OPT_COMMON, {.name = "current", .type = VSH_OT_BOOL, .help = N_("affect current domain") @@ -11381,10 +11327,7 @@ static const vshCmdOptDef opts_detach_disk[] = { }, VSH_DOMAIN_PERSISTENT_OPT_COMMON, VSH_DOMAIN_CONFIG_OPT_COMMON, - {.name = "live", - .type = VSH_OT_BOOL, - .help = N_("affect running domain") - }, + VSH_DOMAIN_LIVE_OPT_COMMON, {.name = "current", .type = VSH_OT_BOOL, .help = N_("affect current domain") -- 2.5.0

Rather than continually cut-n-paste the strings into each command, create a common macro to be used generically. Note that not all '{.name = "current",' entries are replaced, just those that have the common .help string of "affect current domain". Non replaced instances are unique to the command. Signed-off-by: John Ferlan <jferlan@redhat.com> --- tools/virsh-domain.c | 111 +++++++++++++-------------------------------------- 1 file changed, 27 insertions(+), 84 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index c9e8475..3387625 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -88,6 +88,12 @@ .help = N_("affect running domain") \ } \ +#define VSH_DOMAIN_CURRENT_OPT_COMMON \ + {.name = "current", \ + .type = VSH_OT_BOOL, \ + .help = N_("affect current domain") \ + } \ + static virDomainPtr virshLookupDomainInternal(vshControl *ctl, const char *cmdname, @@ -239,10 +245,7 @@ static const vshCmdOptDef opts_attach_device[] = { VSH_DOMAIN_PERSISTENT_OPT_COMMON, VSH_DOMAIN_CONFIG_OPT_COMMON, VSH_DOMAIN_LIVE_OPT_COMMON, - {.name = "current", - .type = VSH_OT_BOOL, - .help = N_("affect current domain") - }, + VSH_DOMAIN_CURRENT_OPT_COMMON, {.name = NULL} }; @@ -393,10 +396,7 @@ static const vshCmdOptDef opts_attach_disk[] = { VSH_DOMAIN_PERSISTENT_OPT_COMMON, VSH_DOMAIN_CONFIG_OPT_COMMON, VSH_DOMAIN_LIVE_OPT_COMMON, - {.name = "current", - .type = VSH_OT_BOOL, - .help = N_("affect current domain") - }, + VSH_DOMAIN_CURRENT_OPT_COMMON, {.name = NULL} }; @@ -844,10 +844,7 @@ static const vshCmdOptDef opts_attach_interface[] = { VSH_DOMAIN_PERSISTENT_OPT_COMMON, VSH_DOMAIN_CONFIG_OPT_COMMON, VSH_DOMAIN_LIVE_OPT_COMMON, - {.name = "current", - .type = VSH_OT_BOOL, - .help = N_("affect current domain") - }, + VSH_DOMAIN_CURRENT_OPT_COMMON, {.name = "print-xml", .type = VSH_OT_BOOL, .help = N_("print XML document rather than attach the interface") @@ -1284,10 +1281,7 @@ static const vshCmdOptDef opts_blkdeviotune[] = { }, VSH_DOMAIN_CONFIG_OPT_COMMON, VSH_DOMAIN_LIVE_OPT_COMMON, - {.name = "current", - .type = VSH_OT_BOOL, - .help = N_("affect current domain") - }, + VSH_DOMAIN_CURRENT_OPT_COMMON, {.name = NULL} }; @@ -1532,10 +1526,7 @@ static const vshCmdOptDef opts_blkiotune[] = { }, VSH_DOMAIN_CONFIG_OPT_COMMON, VSH_DOMAIN_LIVE_OPT_COMMON, - {.name = "current", - .type = VSH_OT_BOOL, - .help = N_("affect current domain") - }, + VSH_DOMAIN_CURRENT_OPT_COMMON, {.name = NULL} }; @@ -3215,10 +3206,7 @@ static const vshCmdOptDef opts_domiftune[] = { }, VSH_DOMAIN_CONFIG_OPT_COMMON, VSH_DOMAIN_LIVE_OPT_COMMON, - {.name = "current", - .type = VSH_OT_BOOL, - .help = N_("affect current domain") - }, + VSH_DOMAIN_CURRENT_OPT_COMMON, {.name = NULL} }; @@ -6397,10 +6385,7 @@ static const vshCmdOptDef opts_vcpupin[] = { }, VSH_DOMAIN_CONFIG_OPT_COMMON, VSH_DOMAIN_LIVE_OPT_COMMON, - {.name = "current", - .type = VSH_OT_BOOL, - .help = N_("affect current domain") - }, + VSH_DOMAIN_CURRENT_OPT_COMMON, {.name = NULL} }; @@ -6595,10 +6580,7 @@ static const vshCmdOptDef opts_emulatorpin[] = { }, VSH_DOMAIN_CONFIG_OPT_COMMON, VSH_DOMAIN_LIVE_OPT_COMMON, - {.name = "current", - .type = VSH_OT_BOOL, - .help = N_("affect current domain") - }, + VSH_DOMAIN_CURRENT_OPT_COMMON, {.name = NULL} }; @@ -6706,10 +6688,7 @@ static const vshCmdOptDef opts_setvcpus[] = { }, VSH_DOMAIN_CONFIG_OPT_COMMON, VSH_DOMAIN_LIVE_OPT_COMMON, - {.name = "current", - .type = VSH_OT_BOOL, - .help = N_("affect current domain") - }, + VSH_DOMAIN_CURRENT_OPT_COMMON, {.name = "guest", .type = VSH_OT_BOOL, .help = N_("modify cpu state in the guest") @@ -6788,10 +6767,7 @@ static const vshCmdOptDef opts_iothreadinfo[] = { VSH_DOMAIN_OPT_COMMON, VSH_DOMAIN_CONFIG_OPT_COMMON, VSH_DOMAIN_LIVE_OPT_COMMON, - {.name = "current", - .type = VSH_OT_BOOL, - .help = N_("affect current domain") - }, + VSH_DOMAIN_CURRENT_OPT_COMMON, {.name = NULL} }; @@ -6877,10 +6853,7 @@ static const vshCmdOptDef opts_iothreadpin[] = { }, VSH_DOMAIN_CONFIG_OPT_COMMON, VSH_DOMAIN_LIVE_OPT_COMMON, - {.name = "current", - .type = VSH_OT_BOOL, - .help = N_("affect current domain") - }, + VSH_DOMAIN_CURRENT_OPT_COMMON, {.name = NULL} }; @@ -6957,10 +6930,7 @@ static const vshCmdOptDef opts_iothreadadd[] = { }, VSH_DOMAIN_CONFIG_OPT_COMMON, VSH_DOMAIN_LIVE_OPT_COMMON, - {.name = "current", - .type = VSH_OT_BOOL, - .help = N_("affect current domain") - }, + VSH_DOMAIN_CURRENT_OPT_COMMON, {.name = NULL} }; @@ -7025,10 +6995,7 @@ static const vshCmdOptDef opts_iothreaddel[] = { }, VSH_DOMAIN_CONFIG_OPT_COMMON, VSH_DOMAIN_LIVE_OPT_COMMON, - {.name = "current", - .type = VSH_OT_BOOL, - .help = N_("affect current domain") - }, + VSH_DOMAIN_CURRENT_OPT_COMMON, {.name = NULL} }; @@ -8281,10 +8248,7 @@ static const vshCmdOptDef opts_setmem[] = { }, VSH_DOMAIN_CONFIG_OPT_COMMON, VSH_DOMAIN_LIVE_OPT_COMMON, - {.name = "current", - .type = VSH_OT_BOOL, - .help = N_("affect current domain") - }, + VSH_DOMAIN_CURRENT_OPT_COMMON, {.name = NULL} }; @@ -8365,10 +8329,7 @@ static const vshCmdOptDef opts_setmaxmem[] = { }, VSH_DOMAIN_CONFIG_OPT_COMMON, VSH_DOMAIN_LIVE_OPT_COMMON, - {.name = "current", - .type = VSH_OT_BOOL, - .help = N_("affect current domain") - }, + VSH_DOMAIN_CURRENT_OPT_COMMON, {.name = NULL} }; @@ -8463,10 +8424,7 @@ static const vshCmdOptDef opts_memtune[] = { }, VSH_DOMAIN_CONFIG_OPT_COMMON, VSH_DOMAIN_LIVE_OPT_COMMON, - {.name = "current", - .type = VSH_OT_BOOL, - .help = N_("affect current domain") - }, + VSH_DOMAIN_CURRENT_OPT_COMMON, {.name = NULL} }; @@ -8636,10 +8594,7 @@ static const vshCmdOptDef opts_numatune[] = { }, VSH_DOMAIN_CONFIG_OPT_COMMON, VSH_DOMAIN_LIVE_OPT_COMMON, - {.name = "current", - .type = VSH_OT_BOOL, - .help = N_("affect current domain") - }, + VSH_DOMAIN_CURRENT_OPT_COMMON, {.name = NULL} }; @@ -10744,10 +10699,7 @@ static const vshCmdOptDef opts_detach_device[] = { VSH_DOMAIN_PERSISTENT_OPT_COMMON, VSH_DOMAIN_CONFIG_OPT_COMMON, VSH_DOMAIN_LIVE_OPT_COMMON, - {.name = "current", - .type = VSH_OT_BOOL, - .help = N_("affect current domain") - }, + VSH_DOMAIN_CURRENT_OPT_COMMON, {.name = NULL} }; @@ -10832,10 +10784,7 @@ static const vshCmdOptDef opts_update_device[] = { VSH_DOMAIN_PERSISTENT_OPT_COMMON, VSH_DOMAIN_CONFIG_OPT_COMMON, VSH_DOMAIN_LIVE_OPT_COMMON, - {.name = "current", - .type = VSH_OT_BOOL, - .help = N_("affect current domain") - }, + VSH_DOMAIN_CURRENT_OPT_COMMON, {.name = "force", .type = VSH_OT_BOOL, .help = N_("force device update") @@ -10925,10 +10874,7 @@ static const vshCmdOptDef opts_detach_interface[] = { VSH_DOMAIN_PERSISTENT_OPT_COMMON, VSH_DOMAIN_CONFIG_OPT_COMMON, VSH_DOMAIN_LIVE_OPT_COMMON, - {.name = "current", - .type = VSH_OT_BOOL, - .help = N_("affect current domain") - }, + VSH_DOMAIN_CURRENT_OPT_COMMON, {.name = NULL} }; @@ -11328,10 +11274,7 @@ static const vshCmdOptDef opts_detach_disk[] = { VSH_DOMAIN_PERSISTENT_OPT_COMMON, VSH_DOMAIN_CONFIG_OPT_COMMON, VSH_DOMAIN_LIVE_OPT_COMMON, - {.name = "current", - .type = VSH_OT_BOOL, - .help = N_("affect current domain") - }, + VSH_DOMAIN_CURRENT_OPT_COMMON, {.name = NULL} }; -- 2.5.0

Rather than continually cut-n-paste the strings into each command, create a common macro to be used generically. Note that not all '{.name = "file",' entries are replaced, just those that use VSH_OT_DATA and VSH_OFLAG_REQ. Replacement of this option is a bit trickier, since the .helpstr changes from command to command. Also because if the N_() I18N for each, it's also not possible to just copy the string. So, replace the enter right side of the .helpstr = with the _helpstr macro argument. Signed-off-by: John Ferlan <jferlan@redhat.com> --- tools/virsh-domain.c | 85 +++++++++++++--------------------------------------- 1 file changed, 20 insertions(+), 65 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 3387625..a055b47 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -94,6 +94,13 @@ .help = N_("affect current domain") \ } \ +#define VSH_DOMAIN_FILE_OPT_COMMON(_helpstr) \ + {.name = "file", \ + .type = VSH_OT_DATA, \ + .flags = VSH_OFLAG_REQ, \ + .help = _helpstr \ + } \ + static virDomainPtr virshLookupDomainInternal(vshControl *ctl, const char *cmdname, @@ -237,11 +244,7 @@ static const vshCmdInfo info_attach_device[] = { static const vshCmdOptDef opts_attach_device[] = { VSH_DOMAIN_OPT_COMMON, - {.name = "file", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("XML file") - }, + VSH_DOMAIN_FILE_OPT_COMMON(N_("XML file")), VSH_DOMAIN_PERSISTENT_OPT_COMMON, VSH_DOMAIN_CONFIG_OPT_COMMON, VSH_DOMAIN_LIVE_OPT_COMMON, @@ -4142,11 +4145,7 @@ static const vshCmdInfo info_save[] = { static const vshCmdOptDef opts_save[] = { VSH_DOMAIN_OPT_COMMON, - {.name = "file", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("where to save the data") - }, + VSH_DOMAIN_FILE_OPT_COMMON(N_("where to save the data")), {.name = "bypass-cache", .type = VSH_OT_BOOL, .help = N_("avoid file system cache when saving") @@ -4403,11 +4402,7 @@ static const vshCmdInfo info_save_image_dumpxml[] = { }; static const vshCmdOptDef opts_save_image_dumpxml[] = { - {.name = "file", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("saved state file to read") - }, + VSH_DOMAIN_FILE_OPT_COMMON(N_("saved state file to read")), {.name = "security-info", .type = VSH_OT_BOOL, .help = N_("include security sensitive information in XML dump") @@ -4456,11 +4451,7 @@ static const vshCmdInfo info_save_image_define[] = { }; static const vshCmdOptDef opts_save_image_define[] = { - {.name = "file", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("saved state file to modify") - }, + VSH_DOMAIN_FILE_OPT_COMMON(N_("saved state file to modify")), {.name = "xml", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -4528,11 +4519,7 @@ static const vshCmdInfo info_save_image_edit[] = { }; static const vshCmdOptDef opts_save_image_edit[] = { - {.name = "file", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("saved state file to edit") - }, + VSH_DOMAIN_FILE_OPT_COMMON(N_("saved state file to edit")), {.name = "running", .type = VSH_OT_BOOL, .help = N_("set domain to be running on restore") @@ -5026,11 +5013,7 @@ static const vshCmdInfo info_restore[] = { }; static const vshCmdOptDef opts_restore[] = { - {.name = "file", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("the state to restore") - }, + VSH_DOMAIN_FILE_OPT_COMMON(N_("the state to restore")), {.name = "bypass-cache", .type = VSH_OT_BOOL, .help = N_("avoid file system cache when restoring") @@ -5107,11 +5090,7 @@ static const vshCmdInfo info_dump[] = { static const vshCmdOptDef opts_dump[] = { VSH_DOMAIN_OPT_COMMON, - {.name = "file", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("where to dump the core") - }, + VSH_DOMAIN_FILE_OPT_COMMON(N_("where to dump the core")), {.name = "live", .type = VSH_OT_BOOL, .help = N_("perform a live core dump if supported") @@ -7052,11 +7031,7 @@ static const vshCmdInfo info_cpu_compare[] = { }; static const vshCmdOptDef opts_cpu_compare[] = { - {.name = "file", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("file containing an XML CPU description") - }, + VSH_DOMAIN_FILE_OPT_COMMON(N_("file containing an XML CPU description")), {.name = "error", .type = VSH_OT_BOOL, .help = N_("report error if CPUs are incompatible") @@ -7154,11 +7129,7 @@ static const vshCmdInfo info_cpu_baseline[] = { }; static const vshCmdOptDef opts_cpu_baseline[] = { - {.name = "file", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("file containing XML CPU descriptions") - }, + VSH_DOMAIN_FILE_OPT_COMMON(N_("file containing XML CPU descriptions")), {.name = "features", .type = VSH_OT_BOOL, .help = N_("Show features that are part of the CPU model type") @@ -7456,11 +7427,7 @@ static const vshCmdInfo info_create[] = { }; static const vshCmdOptDef opts_create[] = { - {.name = "file", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("file containing an XML domain description") - }, + VSH_DOMAIN_FILE_OPT_COMMON(N_("file containing an XML domain description")), #ifndef WIN32 {.name = "console", .type = VSH_OT_BOOL, @@ -7556,11 +7523,7 @@ static const vshCmdInfo info_define[] = { }; static const vshCmdOptDef opts_define[] = { - {.name = "file", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("file containing an XML domain description") - }, + VSH_DOMAIN_FILE_OPT_COMMON(N_("file containing an XML domain description")), {.name = "validate", .type = VSH_OT_BOOL, .help = N_("validate the XML against the schema") @@ -10691,11 +10654,7 @@ static const vshCmdInfo info_detach_device[] = { static const vshCmdOptDef opts_detach_device[] = { VSH_DOMAIN_OPT_COMMON, - {.name = "file", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("XML file") - }, + VSH_DOMAIN_FILE_OPT_COMMON(N_("XML file")), VSH_DOMAIN_PERSISTENT_OPT_COMMON, VSH_DOMAIN_CONFIG_OPT_COMMON, VSH_DOMAIN_LIVE_OPT_COMMON, @@ -10776,11 +10735,7 @@ static const vshCmdInfo info_update_device[] = { static const vshCmdOptDef opts_update_device[] = { VSH_DOMAIN_OPT_COMMON, - {.name = "file", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("XML file") - }, + VSH_DOMAIN_FILE_OPT_COMMON(N_("XML file")), VSH_DOMAIN_PERSISTENT_OPT_COMMON, VSH_DOMAIN_CONFIG_OPT_COMMON, VSH_DOMAIN_LIVE_OPT_COMMON, -- 2.5.0

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 <jferlan@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

Rather than continually cut-n-paste the strings into each command, create common macros to be used generically. Replace the more commonly used "vol" option with a macro. This also adjusts 2 commands that didn't have the correct helpstr - 'vol-create-from' and 'vol-clone'. Both are described in the man page as taking vol, path, or key and the code uses the virshCommandOptVol instead of virshCommandOptVolBy. Signed-off-by: John Ferlan <jferlan@redhat.com> --- tools/virsh-volume.c | 61 ++++++++++++++-------------------------------------- 1 file changed, 16 insertions(+), 45 deletions(-) diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index b88d4c4..9c97c1d 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -62,6 +62,13 @@ .help = N_("pool name or uuid") \ } \ +#define VSH_VOLUME_VOL_OPT_COMMON \ + {.name = "vol", \ + .type = VSH_OT_DATA, \ + .flags = VSH_OFLAG_REQ, \ + .help = N_("vol name, key or path") \ + } \ + virStorageVolPtr virshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd, const char *optname, @@ -441,11 +448,7 @@ static const vshCmdOptDef opts_vol_create_from[] = { .flags = VSH_OFLAG_REQ, .help = N_("file containing an XML vol description") }, - {.name = "vol", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("input vol name or key") - }, + VSH_VOLUME_VOL_OPT_COMMON, {.name = "inputpool", .type = VSH_OT_STRING, .help = N_("pool name or uuid of the input volume's pool") @@ -556,11 +559,7 @@ static const vshCmdInfo info_vol_clone[] = { }; static const vshCmdOptDef opts_vol_clone[] = { - {.name = "vol", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("orig vol name or key") - }, + VSH_VOLUME_VOL_OPT_COMMON, {.name = "newname", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -656,11 +655,7 @@ static const vshCmdInfo info_vol_upload[] = { }; static const vshCmdOptDef opts_vol_upload[] = { - {.name = "vol", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("vol name, key or path") - }, + VSH_VOLUME_VOL_OPT_COMMON, {.name = "file", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -767,11 +762,7 @@ static const vshCmdInfo info_vol_download[] = { }; static const vshCmdOptDef opts_vol_download[] = { - {.name = "vol", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("vol name, key or path") - }, + VSH_VOLUME_VOL_OPT_COMMON, {.name = "file", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -877,11 +868,7 @@ static const vshCmdInfo info_vol_delete[] = { }; static const vshCmdOptDef opts_vol_delete[] = { - {.name = "vol", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("vol name, key or path") - }, + VSH_VOLUME_VOL_OPT_COMMON, VSH_VOLUME_POOL_STRING_OPT_COMMON, {.name = NULL} }; @@ -921,11 +908,7 @@ static const vshCmdInfo info_vol_wipe[] = { }; static const vshCmdOptDef opts_vol_wipe[] = { - {.name = "vol", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("vol name, key or path") - }, + VSH_VOLUME_VOL_OPT_COMMON, VSH_VOLUME_POOL_STRING_OPT_COMMON, {.name = "algorithm", .type = VSH_OT_STRING, @@ -1011,11 +994,7 @@ static const vshCmdInfo info_vol_info[] = { }; static const vshCmdOptDef opts_vol_info[] = { - {.name = "vol", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("vol name, key or path") - }, + VSH_VOLUME_VOL_OPT_COMMON, VSH_VOLUME_POOL_STRING_OPT_COMMON, {.name = NULL} }; @@ -1066,11 +1045,7 @@ static const vshCmdInfo info_vol_resize[] = { }; static const vshCmdOptDef opts_vol_resize[] = { - {.name = "vol", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("vol name, key or path") - }, + VSH_VOLUME_VOL_OPT_COMMON, {.name = "capacity", .type = VSH_OT_DATA, .flags = VSH_OFLAG_REQ, @@ -1167,11 +1142,7 @@ static const vshCmdInfo info_vol_dumpxml[] = { }; static const vshCmdOptDef opts_vol_dumpxml[] = { - {.name = "vol", - .type = VSH_OT_DATA, - .flags = VSH_OFLAG_REQ, - .help = N_("vol name, key or path") - }, + VSH_VOLUME_VOL_OPT_COMMON, VSH_VOLUME_POOL_STRING_OPT_COMMON, {.name = NULL} }; -- 2.5.0

On 17.12.2015 17:55, John Ferlan wrote:
As a follow on to a recent series which created macros for various virsh-*.c command options, see:
http://www.redhat.com/archives/libvir-list/2015-December/msg00672.html
(although best to view by index since there are varying opinions on the matter)...
Modify virsh-domain.c and virsh-volume.c to "follow" the concept of macro-ifying some commonly used options. In order to choose, I used:
$ grep "{.name =" tools/virsh-*.c | \ grep -v "help" | grep -v "desc" | grep -v NULL | \ sort -i | uniq -c | sort -n
To generate a list by module. That generated a list where I randomly picked 9 as the nexus, leaving the following:
9 tools/virsh-domain.c: {.name = "persistent", 10 tools/virsh-snapshot.c: {.name = "domain", 12 tools/virsh-network.c: {.name = "network", 12 tools/virsh-pool.c: {.name = "pool", 13 tools/virsh-volume.c: {.name = "vol", 14 tools/virsh-domain.c: {.name = "file", 14 tools/virsh-domain-monitor.c: {.name = "domain", 14 tools/virsh-volume.c: {.name = "pool", 26 tools/virsh-domain.c: {.name = "current", 28 tools/virsh-domain.c: {.name = "config", 28 tools/virsh-domain.c: {.name = "live", 81 tools/virsh-domain.c: {.name = "domain",
Because virsh-domain-monitor.c, virsh-network.c, and virsh-snapshot.c only had one element with larger counts - I just left them as is and focused on the virsh-domain.c and virsh-volume.c.
The perhaps more controversial choice will be the "file" option in virsh-domain.c which had numerous different helpstr values. I chose to macro-ify them using the entire helpstr including the N_("xxx") rather than just "xxx" since the N_ is the I18N marker.
John Ferlan (8): virsh: Create macro for common "domain" option virsh: Create macro for common "persistent" option virsh: Create macro for common "config" option virsh: Create macro for common "live" option virsh: Create macro for common "current" option virsh: Create macro for common "file" option virsh: Create macros for common "pool" options virsh: Create macros for common "vol" options
tools/virsh-domain.c | 918 +++++++++++---------------------------------------- tools/virsh-volume.c | 155 +++------ 2 files changed, 247 insertions(+), 826 deletions(-)
Apart from Erik's suggestion, I wonder if we should put those definitions into a virsh-wide header so that we don't have to repeat them. For instance, plenty of commands in virsh-domain-monitor.c have --domain too. Other than that this looks very good. Michal
participants (3)
-
Erik Skultety
-
John Ferlan
-
Michal Privoznik