Use the new flags to do the decisions which will also fix the case when
an _INT option is required but non-positional.

This fixes the help for the 'timeout' argument of 'daemon-timeout'
virt-admin command:

     SYNOPSIS
  -    daemon-timeout <timeout>
  +    daemon-timeout --timeout <number>

[...]
     OPTIONS
  -    [--timeout] <number>  number of seconds the daemon will run without any 
active connection
  +    --timeout <number>  number of seconds the daemon will run without any 
active connection

Resolves: https://issues.redhat.com/browse/RHEL-25993
Signed-off-by: Peter Krempa <[email protected]>
---
 tools/vsh.c | 40 +++++++++++++++++++++-------------------
 1 file changed, 21 insertions(+), 19 deletions(-)

diff --git a/tools/vsh.c b/tools/vsh.c
index 521f222910..c7257586e3 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -642,31 +642,33 @@ vshCmddefHelp(const vshCmdDef *def)
     if (def->opts) {
         const vshCmdOptDef *opt;
         for (opt = def->opts; opt->name; opt++) {
-            bool required_option = opt->flags & VSH_OFLAG_REQ;

             switch (opt->type) {
             case VSH_OT_BOOL:
                 fprintf(stdout, " [--%s]", opt->name);
                 break;

+            case VSH_OT_STRING:
+            case VSH_OT_DATA:
             case VSH_OT_INT:
-                if (required_option) {
-                    fprintf(stdout, " <%s>", opt->name);
+                if (opt->required) {
+                    fprintf(stdout, " ");
                 } else {
-                    fprintf(stdout, _(" [--%1$s <number>]"), opt->name);
+                    fprintf(stdout, " [");
                 }
-                break;

-            case VSH_OT_STRING:
-                fprintf(stdout, _(" [--%1$s <string>]"), opt->name);
-                break;
-
-            case VSH_OT_DATA:
-                if (required_option) {
-                    fprintf(stdout, " <%s>", opt->name);
+                if (opt->positional) {
+                    fprintf(stdout, "<%s>", opt->name);
                 } else {
-                    fprintf(stdout, " [<%s>]", opt->name);
+                    if (opt->type == VSH_OT_INT) {
+                        fprintf(stdout, _("--%1$s <number>"), opt->name);
+                    } else {
+                        fprintf(stdout, _("--%1$s <string>"), opt->name);
+                    }
                 }
+
+                if (!opt->required)
+                    fprintf(stdout, "]");
                 break;

             case VSH_OT_ARGV:
@@ -704,7 +706,6 @@ vshCmddefHelp(const vshCmdDef *def)
         const vshCmdOptDef *opt;
         fputs(_("\n  OPTIONS\n"), stdout);
         for (opt = def->opts; opt->name; opt++) {
-            bool required_option = opt->flags & VSH_OFLAG_REQ;
             g_autofree char *optstr = NULL;

             switch (opt->type) {
@@ -713,7 +714,7 @@ vshCmddefHelp(const vshCmdDef *def)
                 break;

             case VSH_OT_INT:
-                if (required_option) {
+                if (opt->positional) {
                     optstr = g_strdup_printf(_("[--%1$s] <number>"), 
opt->name);
                 } else {
                     optstr = g_strdup_printf(_("--%1$s <number>"), opt->name);
@@ -721,11 +722,12 @@ vshCmddefHelp(const vshCmdDef *def)
                 break;

             case VSH_OT_STRING:
-                optstr = g_strdup_printf(_("--%1$s <string>"), opt->name);
-                break;
-
             case VSH_OT_DATA:
-                optstr = g_strdup_printf(_("[--%1$s] <string>"), opt->name);
+                if (opt->positional) {
+                    optstr = g_strdup_printf(_("[--%1$s] <string>"), 
opt->name);
+                } else {
+                    optstr = g_strdup_printf(_("--%1$s <string>"), opt->name);
+                }
                 break;

             case VSH_OT_ARGV:
-- 
2.44.0
_______________________________________________
Devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to