* and only relies on static data accessible from the user-side callback
*/
const vshCmdGrp *cmdGroups;
-const vshCmdDef *cmdSet;
double
return -1;
}
-static const vshCmdDef *
-vshCmdDefSearchGrp(const char *cmdname)
+const vshCmdDef *
+vshCmddefSearch(const char *cmdname)
{
const vshCmdGrp *g;
const vshCmdDef *c;
return NULL;
}
-static const vshCmdDef *
-vshCmdDefSearchSet(const char *cmdname)
-{
- const vshCmdDef *s;
-
- for (s = cmdSet; s->name; s++) {
- if (STREQ(s->name, cmdname))
- return s;
- }
-
- return NULL;
-}
-
-const vshCmdDef *
-vshCmddefSearch(const char *cmdname)
-{
- if (cmdGroups)
- return vshCmdDefSearchGrp(cmdname);
- else
- return vshCmdDefSearchSet(cmdname);
-}
-
const vshCmdGrp *
vshCmdGrpSearch(const char *grpname)
{
if (cmd->flags & VSH_CMD_FLAG_ALIAS) {
VIR_FREE(tkdata);
tkdata = g_strdup(cmd->alias);
- cmd = vshCmddefSearch(tkdata);
+ if (!(cmd = vshCmddefSearch(tkdata))) {
+ /* self-test ensures that the alias exists */
+ vshError(ctl, _("unknown command: '%1$s'"), tkdata);
+ goto syntaxError;
+ }
}
vshCmddefOptParse(cmd, &opts_need_arg, &opts_required);
if (STRNEQ(tmpopt->def->name, "help"))
continue;
- help = vshCmddefSearch("help");
+ /* the self-test code ensures that help exists */
+ if (!(help = vshCmddefSearch("help")))
+ break;
+
vshCommandOptFree(first);
first = g_new0(vshCmdOpt, 1);
first->def = help->opts;
* Initialize global data
*/
bool
-vshInit(vshControl *ctl, const vshCmdGrp *groups, const vshCmdDef *set)
+vshInit(vshControl *ctl, const vshCmdGrp *groups)
{
if (!ctl->hooks) {
vshError(ctl, "%s", _("client hooks cannot be NULL"));
return false;
}
- if (!groups && !set) {
- vshError(ctl, "%s", _("command groups and command set cannot both be NULL"));
+ if (!groups) {
+ vshError(ctl, "%s", _("command groups must be non-NULL"));
return false;
}
cmdGroups = groups;
- cmdSet = set;
if (vshInitDebug(ctl) < 0 ||
(ctl->imode && vshReadlineInit(ctl) < 0))
bool
vshInitReload(vshControl *ctl)
{
- if (!cmdGroups && !cmdSet) {
- vshError(ctl, "%s", _("command groups and command are both NULL run vshInit before reloading"));
+ if (!cmdGroups) {
+ vshError(ctl, "%s", _("command groups is NULL run vshInit before reloading"));
return false;
}
if ((def = vshCmddefSearch(name))) {
if (def->flags & VSH_CMD_FLAG_ALIAS)
def = vshCmddefSearch(def->alias);
+ }
+
+ if (def) {
return vshCmddefHelp(def);
} else if ((grp = vshCmdGrpSearch(name))) {
return vshCmdGrpHelp(ctl, grp);
G_GNUC_PRINTF(2, 3);
void vshPrintExtra(vshControl *ctl, const char *format, ...)
G_GNUC_PRINTF(2, 3);
-bool vshInit(vshControl *ctl, const vshCmdGrp *groups, const vshCmdDef *set);
+bool vshInit(vshControl *ctl, const vshCmdGrp *groups);
bool vshInitReload(vshControl *ctl);
void vshDeinit(vshControl *ctl);
void vshDebug(vshControl *ctl, int level, const char *format, ...)