[PATCH 11/23] vshCmddefHelp: Refactor printing of help (list of arguments)

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

 



Extract flag check to a separate variable and replace ternary operators
by normal conditions and directly output the text rather than using
extra variable to improve readability.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 tools/vsh.c | 48 ++++++++++++++++++++++++++++++++----------------
 1 file changed, 32 insertions(+), 16 deletions(-)

diff --git a/tools/vsh.c b/tools/vsh.c
index 688161beda..add50fe670 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -630,47 +630,63 @@ vshCmddefHelp(const vshCmdDef *def)
     if (def->opts) {
         const vshCmdOptDef *opt;
         for (opt = def->opts; opt->name; opt++) {
-            const char *fmt = "%s";
+            bool required_option = opt->flags & VSH_OFLAG_REQ;
+
             switch (opt->type) {
             case VSH_OT_BOOL:
-                fmt = "[--%s]";
+                fprintf(stdout, " [--%s]", opt->name);
                 break;
+
             case VSH_OT_INT:
-                /* xgettext:c-format */
-                fmt = ((opt->flags & VSH_OFLAG_REQ) ? "<%s>"
-                       : _("[--%1$s <number>]"));
+                if (required_option) {
+                    fprintf(stdout, " <%s>", opt->name);
+                } else {
+                    fprintf(stdout, _(" [--%1$s <number>]"), opt->name);
+                }
+
                 if (!(opt->flags & VSH_OFLAG_REQ_OPT))
                     shortopt = true;
                 break;
+
             case VSH_OT_STRING:
-                /* xgettext:c-format */
-                fmt = _("[--%1$s <string>]");
+                fprintf(stdout, _(" [--%1$s <string>]"), opt->name);
+
                 if (!(opt->flags & VSH_OFLAG_REQ_OPT))
                     shortopt = true;
                 break;
+
             case VSH_OT_DATA:
-                fmt = ((opt->flags & VSH_OFLAG_REQ) ? "<%s>" : "[<%s>]");
+                if (required_option) {
+                    fprintf(stdout, " <%s>", opt->name);
+                } else {
+                    fprintf(stdout, " [<%s>]", opt->name);
+                }
+
                 if (!(opt->flags & VSH_OFLAG_REQ_OPT))
                     shortopt = true;
                 break;
+
             case VSH_OT_ARGV:
-                /* xgettext:c-format */
                 if (shortopt) {
-                    fmt = (opt->flags & VSH_OFLAG_REQ)
-                        ? _("{[--%1$s] <string>}...")
-                        : _("[[--%1$s] <string>]...");
+                    if (required_option) {
+                        fprintf(stdout, _(" {[--%1$s] <string>}..."), opt->name);
+                    } else {
+                        fprintf(stdout, _(" [[--%1$s] <string>]..."), opt->name);
+                    }
                 } else {
-                    fmt = (opt->flags & VSH_OFLAG_REQ) ? _("<%1$s>...")
-                        : _("[<%1$s>]...");
+                    if (required_option) {
+                        fprintf(stdout, " <%s>...", opt->name);
+                    } else {
+                        fprintf(stdout, " [<%s>]...", opt->name);
+                    }
                 }
                 break;
+
             case VSH_OT_ALIAS:
             case VSH_OT_NONE:
                 /* aliases are intentionally undocumented */
                 continue;
             }
-            fputc(' ', stdout);
-            fprintf(stdout, fmt, opt->name);
         }
     }
     fputc('\n', stdout);
-- 
2.44.0
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[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]

  Powered by Linux