combine help and usage command handlers
Remove duplicated handler code by checking the running command name.__archive__
parent
c297a14f70
commit
910bb250c4
|
@ -861,30 +861,18 @@ static COMMAND_HELPER(command_help_show, struct command *c, unsigned n,
|
||||||
}
|
}
|
||||||
COMMAND_HANDLER(handle_help_command)
|
COMMAND_HANDLER(handle_help_command)
|
||||||
{
|
{
|
||||||
|
bool full = strcmp(CMD_NAME, "help") == 0;
|
||||||
|
|
||||||
struct command *c = CMD_CTX->commands;
|
struct command *c = CMD_CTX->commands;
|
||||||
|
|
||||||
if (0 == CMD_ARGC)
|
if (0 == CMD_ARGC)
|
||||||
return CALL_COMMAND_HANDLER(command_help_show_list, c, 0, true);
|
return CALL_COMMAND_HANDLER(command_help_show_list, c, 0, full);
|
||||||
|
|
||||||
int retval = CALL_COMMAND_HANDLER(command_help_find, c, &c);
|
int retval = CALL_COMMAND_HANDLER(command_help_find, c, &c);
|
||||||
if (ERROR_OK != retval)
|
if (ERROR_OK != retval)
|
||||||
return retval;
|
return retval;
|
||||||
|
|
||||||
return CALL_COMMAND_HANDLER(command_help_show, c, 0, true);
|
return CALL_COMMAND_HANDLER(command_help_show, c, 0, full);
|
||||||
}
|
|
||||||
|
|
||||||
COMMAND_HANDLER(handle_usage_command)
|
|
||||||
{
|
|
||||||
struct command *c = CMD_CTX->commands;
|
|
||||||
|
|
||||||
if (0 == CMD_ARGC)
|
|
||||||
return CALL_COMMAND_HANDLER(command_help_show_list, c, 0, false);
|
|
||||||
|
|
||||||
int retval = CALL_COMMAND_HANDLER(command_help_find, c, &c);
|
|
||||||
if (ERROR_OK != retval)
|
|
||||||
return retval;
|
|
||||||
|
|
||||||
return CALL_COMMAND_HANDLER(command_help_show, c, 0, false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int command_unknown_find(unsigned argc, Jim_Obj *const *argv,
|
static int command_unknown_find(unsigned argc, Jim_Obj *const *argv,
|
||||||
|
@ -1106,15 +1094,15 @@ static const struct command_registration command_builtin_handlers[] = {
|
||||||
.name = "help",
|
.name = "help",
|
||||||
.handler = &handle_help_command,
|
.handler = &handle_help_command,
|
||||||
.mode = COMMAND_ANY,
|
.mode = COMMAND_ANY,
|
||||||
.help = "show built-in command help",
|
.help = "show full command help",
|
||||||
.usage = "[<command_name> ...]",
|
.usage = "[<command> ...]",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
.name = "usage",
|
.name = "usage",
|
||||||
.handler = &handle_usage_command,
|
.handler = &handle_help_command,
|
||||||
.mode = COMMAND_ANY,
|
.mode = COMMAND_ANY,
|
||||||
.help = "show command usage",
|
.help = "show basic command usage",
|
||||||
.usage = "[<command_name> ...]",
|
.usage = "[<command> ...]",
|
||||||
},
|
},
|
||||||
COMMAND_REGISTRATION_DONE
|
COMMAND_REGISTRATION_DONE
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue