vshCmdGrpHelp: Refactor formatting of help for VSH_OT_ARGV

Use the new properties rather than infer the states.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2024-03-05 16:32:40 +01:00
parent 55a07252ec
commit e177b0fca6

View File

@ -634,8 +634,6 @@ vshCmdGrpHelp(vshControl *ctl, const vshCmdGrp *grp)
static bool static bool
vshCmddefHelp(const vshCmdDef *def) vshCmddefHelp(const vshCmdDef *def)
{ {
bool shortopt = false; /* true if 'arg' works instead of '--opt arg' */
fputs(_(" NAME\n"), stdout); fputs(_(" NAME\n"), stdout);
fprintf(stdout, " %s - %s\n", def->name, _(def->info->help)); fprintf(stdout, " %s - %s\n", def->name, _(def->info->help));
@ -657,16 +655,10 @@ vshCmddefHelp(const vshCmdDef *def)
} else { } else {
fprintf(stdout, _(" [--%1$s <number>]"), opt->name); fprintf(stdout, _(" [--%1$s <number>]"), opt->name);
} }
if (!(opt->flags & VSH_OFLAG_REQ_OPT))
shortopt = true;
break; break;
case VSH_OT_STRING: case VSH_OT_STRING:
fprintf(stdout, _(" [--%1$s <string>]"), opt->name); fprintf(stdout, _(" [--%1$s <string>]"), opt->name);
if (!(opt->flags & VSH_OFLAG_REQ_OPT))
shortopt = true;
break; break;
case VSH_OT_DATA: case VSH_OT_DATA:
@ -675,24 +667,21 @@ vshCmddefHelp(const vshCmdDef *def)
} else { } else {
fprintf(stdout, " [<%s>]", opt->name); fprintf(stdout, " [<%s>]", opt->name);
} }
if (!(opt->flags & VSH_OFLAG_REQ_OPT))
shortopt = true;
break; break;
case VSH_OT_ARGV: case VSH_OT_ARGV:
if (shortopt) { if (opt->positional) {
if (required_option) { if (opt->required) {
fprintf(stdout, _(" {[--%1$s] <string>}..."), opt->name);
} else {
fprintf(stdout, _(" [[--%1$s] <string>]..."), opt->name);
}
} else {
if (required_option) {
fprintf(stdout, " <%s>...", opt->name); fprintf(stdout, " <%s>...", opt->name);
} else { } else {
fprintf(stdout, " [<%s>]...", opt->name); fprintf(stdout, " [<%s>]...", opt->name);
} }
} else {
if (opt->required) {
fprintf(stdout, _(" {[--%1$s] <string>}..."), opt->name);
} else {
fprintf(stdout, _(" [[--%1$s] <string>]..."), opt->name);
}
} }
break; break;
@ -740,10 +729,10 @@ vshCmddefHelp(const vshCmdDef *def)
break; break;
case VSH_OT_ARGV: case VSH_OT_ARGV:
if (shortopt) { if (opt->positional) {
optstr = g_strdup_printf(_("[--%1$s] <string>"), opt->name);
} else {
optstr = g_strdup_printf("<%s>", opt->name); optstr = g_strdup_printf("<%s>", opt->name);
} else {
optstr = g_strdup_printf(_("[--%1$s] <string>"), opt->name);
} }
break; break;