提交 9b86282e 编写于 作者: E Erik Skultety

vsh: vshCmddefHelp: Drop the unnecessary 'else' branch

If the initial check is true the function immediately returns so there's no
need to enclose the code following the check within an 'else' block.
Also, by removing the 'else' block, the declarations need to be moved to
beginning of the function block to conform with our guidelines.
Signed-off-by: NErik Skultety <eskultet@redhat.com>
上级 c91cddb6
...@@ -629,131 +629,131 @@ bool ...@@ -629,131 +629,131 @@ bool
vshCmddefHelp(vshControl *ctl, const char *cmdname) vshCmddefHelp(vshControl *ctl, const char *cmdname)
{ {
const vshCmdDef *def = vshCmddefSearch(cmdname); const vshCmdDef *def = vshCmddefSearch(cmdname);
const char *desc = NULL;
char buf[256];
uint64_t opts_need_arg;
uint64_t opts_required;
bool shortopt = false; /* true if 'arg' works instead of '--opt arg' */
if (!def) { if (!def) {
vshError(ctl, _("command '%s' doesn't exist"), cmdname); vshError(ctl, _("command '%s' doesn't exist"), cmdname);
return false; return false;
} else { }
/* Don't translate desc if it is "". */
const char *desc = vshCmddefGetInfo(def, "desc");
char buf[256];
uint64_t opts_need_arg;
uint64_t opts_required;
bool shortopt = false; /* true if 'arg' works instead of '--opt arg' */
if (vshCmddefOptParse(def, &opts_need_arg, &opts_required)) {
vshError(ctl, _("internal error: bad options in command: '%s'"),
def->name);
return false;
}
fputs(_(" NAME\n"), stdout); if (vshCmddefOptParse(def, &opts_need_arg, &opts_required)) {
fprintf(stdout, " %s - %s\n", def->name, vshError(ctl, _("internal error: bad options in command: '%s'"),
_(vshCmddefGetInfo(def, "help"))); def->name);
return false;
fputs(_("\n SYNOPSIS\n"), stdout); }
fprintf(stdout, " %s", def->name);
if (def->opts) { fputs(_(" NAME\n"), stdout);
const vshCmdOptDef *opt; fprintf(stdout, " %s - %s\n", def->name,
for (opt = def->opts; opt->name; opt++) { _(vshCmddefGetInfo(def, "help")));
const char *fmt = "%s";
switch (opt->type) { fputs(_("\n SYNOPSIS\n"), stdout);
case VSH_OT_BOOL: fprintf(stdout, " %s", def->name);
fmt = "[--%s]"; if (def->opts) {
break; const vshCmdOptDef *opt;
case VSH_OT_INT: for (opt = def->opts; opt->name; opt++) {
/* xgettext:c-format */ const char *fmt = "%s";
fmt = ((opt->flags & VSH_OFLAG_REQ) ? "<%s>" switch (opt->type) {
: _("[--%s <number>]")); case VSH_OT_BOOL:
if (!(opt->flags & VSH_OFLAG_REQ_OPT)) fmt = "[--%s]";
shortopt = true; break;
break; case VSH_OT_INT:
case VSH_OT_STRING: /* xgettext:c-format */
/* xgettext:c-format */ fmt = ((opt->flags & VSH_OFLAG_REQ) ? "<%s>"
fmt = _("[--%s <string>]"); : _("[--%s <number>]"));
if (!(opt->flags & VSH_OFLAG_REQ_OPT)) if (!(opt->flags & VSH_OFLAG_REQ_OPT))
shortopt = true; shortopt = true;
break; break;
case VSH_OT_DATA: case VSH_OT_STRING:
fmt = ((opt->flags & VSH_OFLAG_REQ) ? "<%s>" : "[<%s>]"); /* xgettext:c-format */
if (!(opt->flags & VSH_OFLAG_REQ_OPT)) fmt = _("[--%s <string>]");
shortopt = true; if (!(opt->flags & VSH_OFLAG_REQ_OPT))
break; shortopt = true;
case VSH_OT_ARGV: break;
/* xgettext:c-format */ case VSH_OT_DATA:
if (shortopt) { fmt = ((opt->flags & VSH_OFLAG_REQ) ? "<%s>" : "[<%s>]");
fmt = (opt->flags & VSH_OFLAG_REQ) if (!(opt->flags & VSH_OFLAG_REQ_OPT))
? _("{[--%s] <string>}...") shortopt = true;
: _("[[--%s] <string>]..."); break;
} else { case VSH_OT_ARGV:
fmt = (opt->flags & VSH_OFLAG_REQ) ? _("<%s>...") /* xgettext:c-format */
: _("[<%s>]..."); if (shortopt) {
} fmt = (opt->flags & VSH_OFLAG_REQ)
break; ? _("{[--%s] <string>}...")
case VSH_OT_ALIAS: : _("[[--%s] <string>]...");
/* aliases are intentionally undocumented */ } else {
continue; fmt = (opt->flags & VSH_OFLAG_REQ) ? _("<%s>...")
: _("[<%s>]...");
} }
fputc(' ', stdout); break;
fprintf(stdout, fmt, opt->name); case VSH_OT_ALIAS:
/* aliases are intentionally undocumented */
continue;
} }
fputc(' ', stdout);
fprintf(stdout, fmt, opt->name);
} }
fputc('\n', stdout); }
fputc('\n', stdout);
if (desc[0]) { desc = vshCmddefGetInfo(def, "desc");
/* Print the description only if it's not empty. */ if (*desc) {
fputs(_("\n DESCRIPTION\n"), stdout); /* Print the description only if it's not empty. */
fprintf(stdout, " %s\n", _(desc)); fputs(_("\n DESCRIPTION\n"), stdout);
} fprintf(stdout, " %s\n", _(desc));
}
if (def->opts && def->opts->name) { if (def->opts && def->opts->name) {
const vshCmdOptDef *opt; const vshCmdOptDef *opt;
fputs(_("\n OPTIONS\n"), stdout); fputs(_("\n OPTIONS\n"), stdout);
for (opt = def->opts; opt->name; opt++) { for (opt = def->opts; opt->name; opt++) {
switch (opt->type) { switch (opt->type) {
case VSH_OT_BOOL: case VSH_OT_BOOL:
snprintf(buf, sizeof(buf), "--%s", opt->name); snprintf(buf, sizeof(buf), "--%s", opt->name);
break; break;
case VSH_OT_INT: case VSH_OT_INT:
snprintf(buf, sizeof(buf), snprintf(buf, sizeof(buf),
(opt->flags & VSH_OFLAG_REQ) ? _("[--%s] <number>") (opt->flags & VSH_OFLAG_REQ) ? _("[--%s] <number>")
: _("--%s <number>"), opt->name); : _("--%s <number>"), opt->name);
break; break;
case VSH_OT_STRING: case VSH_OT_STRING:
/* OT_STRING should never be VSH_OFLAG_REQ */ /* OT_STRING should never be VSH_OFLAG_REQ */
if (opt->flags & VSH_OFLAG_REQ) { if (opt->flags & VSH_OFLAG_REQ) {
vshError(ctl, vshError(ctl,
_("internal error: bad options in command: '%s'"), _("internal error: bad options in command: '%s'"),
def->name); def->name);
return false; return false;
}
snprintf(buf, sizeof(buf), _("--%s <string>"), opt->name);
break;
case VSH_OT_DATA:
/* OT_DATA should always be VSH_OFLAG_REQ */
if (!(opt->flags & VSH_OFLAG_REQ)) {
vshError(ctl,
_("internal error: bad options in command: '%s'"),
def->name);
return false;
}
snprintf(buf, sizeof(buf), _("[--%s] <string>"),
opt->name);
break;
case VSH_OT_ARGV:
snprintf(buf, sizeof(buf),
shortopt ? _("[--%s] <string>") : _("<%s>"),
opt->name);
break;
case VSH_OT_ALIAS:
continue;
} }
snprintf(buf, sizeof(buf), _("--%s <string>"), opt->name);
fprintf(stdout, " %-15s %s\n", buf, _(opt->help)); break;
case VSH_OT_DATA:
/* OT_DATA should always be VSH_OFLAG_REQ */
if (!(opt->flags & VSH_OFLAG_REQ)) {
vshError(ctl,
_("internal error: bad options in command: '%s'"),
def->name);
return false;
}
snprintf(buf, sizeof(buf), _("[--%s] <string>"),
opt->name);
break;
case VSH_OT_ARGV:
snprintf(buf, sizeof(buf),
shortopt ? _("[--%s] <string>") : _("<%s>"),
opt->name);
break;
case VSH_OT_ALIAS:
continue;
} }
fprintf(stdout, " %-15s %s\n", buf, _(opt->help));
} }
fputc('\n', stdout);
} }
fputc('\n', stdout);
return true; return true;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册