}
bool
-vshCmdGrpHelp(vshControl *ctl, const char *grpname)
+vshCmdGrpHelp(vshControl *ctl, const vshCmdGrp *grp)
{
- const vshCmdGrp *grp = vshCmdGrpSearch(grpname);
const vshCmdDef *cmd = NULL;
- if (!grp) {
- vshError(ctl, _("command group '%s' doesn't exist"), grpname);
- return false;
- } else {
- vshPrint(ctl, _(" %s (help keyword '%s'):\n"), grp->name,
- grp->keyword);
+ vshPrint(ctl, _(" %s (help keyword '%s'):\n"), grp->name,
+ grp->keyword);
- for (cmd = grp->commands; cmd->name; cmd++) {
- if (cmd->flags & VSH_CMD_FLAG_ALIAS)
- continue;
- vshPrint(ctl, " %-30s %s\n", cmd->name,
- _(vshCmddefGetInfo(cmd, "help")));
- }
+ for (cmd = grp->commands; cmd->name; cmd++) {
+ if (cmd->flags & VSH_CMD_FLAG_ALIAS)
+ continue;
+ vshPrint(ctl, " %-30s %s\n", cmd->name,
+ _(vshCmddefGetInfo(cmd, "help")));
}
return true;
}
bool
-vshCmddefHelp(vshControl *ctl, const char *cmdname)
+vshCmddefHelp(vshControl *ctl, const vshCmdDef *def)
{
- 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) {
- vshError(ctl, _("command '%s' doesn't exist"), cmdname);
- return false;
- }
-
if (vshCmddefOptParse(def, &opts_need_arg, &opts_required)) {
vshError(ctl, _("internal error: bad options in command: '%s'"),
def->name);
bool
cmdHelp(vshControl *ctl, const vshCmd *cmd)
{
+ const vshCmdDef *def = NULL;
+ const vshCmdGrp *grp = NULL;
const char *name = NULL;
if (vshCommandOptStringQuiet(ctl, cmd, "command", &name) <= 0) {
- const vshCmdGrp *grp;
- const vshCmdDef *def;
-
vshPrint(ctl, "%s", _("Grouped commands:\n\n"));
for (grp = cmdGroups; grp->name; grp++) {
return true;
}
- if (vshCmddefSearch(name)) {
- return vshCmddefHelp(ctl, name);
- } else if (vshCmdGrpSearch(name)) {
- return vshCmdGrpHelp(ctl, name);
+ if ((def = vshCmddefSearch(name))) {
+ return vshCmddefHelp(ctl, def);
+ } else if ((grp = vshCmdGrpSearch(name))) {
+ return vshCmdGrpHelp(ctl, grp);
} else {
vshError(ctl, _("command or command group '%s' doesn't exist"), name);
return false;
const char *vshCmddefGetInfo(const vshCmdDef *cmd, const char *info);
const vshCmdDef *vshCmddefSearch(const char *cmdname);
-bool vshCmddefHelp(vshControl *ctl, const char *name);
+bool vshCmddefHelp(vshControl *ctl, const vshCmdDef *def);
const vshCmdGrp *vshCmdGrpSearch(const char *grpname);
-bool vshCmdGrpHelp(vshControl *ctl, const char *name);
+bool vshCmdGrpHelp(vshControl *ctl, const vshCmdGrp *grp);
int vshCommandOptInt(vshControl *ctl, const vshCmd *cmd,
const char *name, int *value)