From e177b0fca66f569cb05ce408b36a5d248f95b0e2 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Tue, 5 Mar 2024 16:32:40 +0100 Subject: [PATCH] vshCmdGrpHelp: Refactor formatting of help for VSH_OT_ARGV MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the new properties rather than infer the states. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- tools/vsh.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/tools/vsh.c b/tools/vsh.c index e80c6e84f1..1907e778f2 100644 --- a/tools/vsh.c +++ b/tools/vsh.c @@ -634,8 +634,6 @@ vshCmdGrpHelp(vshControl *ctl, const vshCmdGrp *grp) static bool vshCmddefHelp(const vshCmdDef *def) { - bool shortopt = false; /* true if 'arg' works instead of '--opt arg' */ - fputs(_(" NAME\n"), stdout); fprintf(stdout, " %s - %s\n", def->name, _(def->info->help)); @@ -657,16 +655,10 @@ vshCmddefHelp(const vshCmdDef *def) } else { fprintf(stdout, _(" [--%1$s ]"), opt->name); } - - if (!(opt->flags & VSH_OFLAG_REQ_OPT)) - shortopt = true; break; case VSH_OT_STRING: fprintf(stdout, _(" [--%1$s ]"), opt->name); - - if (!(opt->flags & VSH_OFLAG_REQ_OPT)) - shortopt = true; break; case VSH_OT_DATA: @@ -675,24 +667,21 @@ vshCmddefHelp(const vshCmdDef *def) } else { fprintf(stdout, " [<%s>]", opt->name); } - - if (!(opt->flags & VSH_OFLAG_REQ_OPT)) - shortopt = true; break; case VSH_OT_ARGV: - if (shortopt) { - if (required_option) { - fprintf(stdout, _(" {[--%1$s] }..."), opt->name); - } else { - fprintf(stdout, _(" [[--%1$s] ]..."), opt->name); - } - } else { - if (required_option) { + if (opt->positional) { + if (opt->required) { fprintf(stdout, " <%s>...", opt->name); } else { fprintf(stdout, " [<%s>]...", opt->name); } + } else { + if (opt->required) { + fprintf(stdout, _(" {[--%1$s] }..."), opt->name); + } else { + fprintf(stdout, _(" [[--%1$s] ]..."), opt->name); + } } break; @@ -740,10 +729,10 @@ vshCmddefHelp(const vshCmdDef *def) break; case VSH_OT_ARGV: - if (shortopt) { - optstr = g_strdup_printf(_("[--%1$s] "), opt->name); - } else { + if (opt->positional) { optstr = g_strdup_printf("<%s>", opt->name); + } else { + optstr = g_strdup_printf(_("[--%1$s] "), opt->name); } break;