[PATCH v3 08/14] virsh: Create macro for common "file" option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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 e3ed216..ce698c3 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -87,6 +87,13 @@
      .help = N_("affect current domain")               \
     }                                                  \
 
+#define VIRSH_COMMON_OPT_DOMAIN_FILE(_helpstr)         \
+    {.name = "file",                                   \
+     .type = VSH_OT_DATA,                              \
+     .flags = VSH_OFLAG_REQ,                           \
+     .help = _helpstr                                  \
+    }                                                  \
+
 static virDomainPtr
 virshLookupDomainInternal(vshControl *ctl,
                           const char *cmdname,
@@ -230,11 +237,7 @@ static const vshCmdInfo info_attach_device[] = {
 
 static const vshCmdOptDef opts_attach_device[] = {
     VIRSH_COMMON_OPT_DOMAIN,
-    {.name = "file",
-     .type = VSH_OT_DATA,
-     .flags = VSH_OFLAG_REQ,
-     .help = N_("XML file")
-    },
+    VIRSH_COMMON_OPT_DOMAIN_FILE(N_("XML file")),
     VIRSH_COMMON_OPT_DOMAIN_PERSISTENT,
     VIRSH_COMMON_OPT_DOMAIN_CONFIG,
     VIRSH_COMMON_OPT_DOMAIN_LIVE,
@@ -4147,11 +4150,7 @@ static const vshCmdInfo info_save[] = {
 
 static const vshCmdOptDef opts_save[] = {
     VIRSH_COMMON_OPT_DOMAIN,
-    {.name = "file",
-     .type = VSH_OT_DATA,
-     .flags = VSH_OFLAG_REQ,
-     .help = N_("where to save the data")
-    },
+    VIRSH_COMMON_OPT_DOMAIN_FILE(N_("where to save the data")),
     {.name = "bypass-cache",
      .type = VSH_OT_BOOL,
      .help = N_("avoid file system cache when saving")
@@ -4408,11 +4407,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")
-    },
+    VIRSH_COMMON_OPT_DOMAIN_FILE(N_("saved state file to read")),
     {.name = "security-info",
      .type = VSH_OT_BOOL,
      .help = N_("include security sensitive information in XML dump")
@@ -4461,11 +4456,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")
-    },
+    VIRSH_COMMON_OPT_DOMAIN_FILE(N_("saved state file to modify")),
     {.name = "xml",
      .type = VSH_OT_DATA,
      .flags = VSH_OFLAG_REQ,
@@ -4533,11 +4524,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")
-    },
+    VIRSH_COMMON_OPT_DOMAIN_FILE(N_("saved state file to edit")),
     {.name = "running",
      .type = VSH_OT_BOOL,
      .help = N_("set domain to be running on restore")
@@ -5031,11 +5018,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")
-    },
+    VIRSH_COMMON_OPT_DOMAIN_FILE(N_("the state to restore")),
     {.name = "bypass-cache",
      .type = VSH_OT_BOOL,
      .help = N_("avoid file system cache when restoring")
@@ -5112,11 +5095,7 @@ static const vshCmdInfo info_dump[] = {
 
 static const vshCmdOptDef opts_dump[] = {
     VIRSH_COMMON_OPT_DOMAIN,
-    {.name = "file",
-     .type = VSH_OT_DATA,
-     .flags = VSH_OFLAG_REQ,
-     .help = N_("where to dump the core")
-    },
+    VIRSH_COMMON_OPT_DOMAIN_FILE(N_("where to dump the core")),
     {.name = "live",
      .type = VSH_OT_BOOL,
      .help = N_("perform a live core dump if supported")
@@ -7073,11 +7052,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")
-    },
+    VIRSH_COMMON_OPT_DOMAIN_FILE(N_("file containing an XML CPU description")),
     {.name = "error",
      .type = VSH_OT_BOOL,
      .help = N_("report error if CPUs are incompatible")
@@ -7175,11 +7150,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")
-    },
+    VIRSH_COMMON_OPT_DOMAIN_FILE(N_("file containing XML CPU descriptions")),
     {.name = "features",
      .type = VSH_OT_BOOL,
      .help = N_("Show features that are part of the CPU model type")
@@ -7477,11 +7448,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")
-    },
+    VIRSH_COMMON_OPT_DOMAIN_FILE(N_("file containing an XML domain description")),
 #ifndef WIN32
     {.name = "console",
      .type = VSH_OT_BOOL,
@@ -7577,11 +7544,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")
-    },
+    VIRSH_COMMON_OPT_DOMAIN_FILE(N_("file containing an XML domain description")),
     {.name = "validate",
      .type = VSH_OT_BOOL,
      .help = N_("validate the XML against the schema")
@@ -10716,11 +10679,7 @@ static const vshCmdInfo info_detach_device[] = {
 
 static const vshCmdOptDef opts_detach_device[] = {
     VIRSH_COMMON_OPT_DOMAIN,
-    {.name = "file",
-     .type = VSH_OT_DATA,
-     .flags = VSH_OFLAG_REQ,
-     .help = N_("XML file")
-    },
+    VIRSH_COMMON_OPT_DOMAIN_FILE(N_("XML file")),
     VIRSH_COMMON_OPT_DOMAIN_PERSISTENT,
     VIRSH_COMMON_OPT_DOMAIN_CONFIG,
     VIRSH_COMMON_OPT_DOMAIN_LIVE,
@@ -10801,11 +10760,7 @@ static const vshCmdInfo info_update_device[] = {
 
 static const vshCmdOptDef opts_update_device[] = {
     VIRSH_COMMON_OPT_DOMAIN,
-    {.name = "file",
-     .type = VSH_OT_DATA,
-     .flags = VSH_OFLAG_REQ,
-     .help = N_("XML file")
-    },
+    VIRSH_COMMON_OPT_DOMAIN_FILE(N_("XML file")),
     VIRSH_COMMON_OPT_DOMAIN_PERSISTENT,
     VIRSH_COMMON_OPT_DOMAIN_CONFIG,
     VIRSH_COMMON_OPT_DOMAIN_LIVE,
-- 
2.5.0

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



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]