Skip to content

Commit

Permalink
Added Help command parameter for displaying only a specific command
Browse files Browse the repository at this point in the history
  • Loading branch information
jnorgan committed Jul 24, 2023
1 parent 9a1cc59 commit 25fb324
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions components/console/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,33 @@ esp_err_t esp_console_run(const char *cmdline, int *cmd_ret)
return ESP_OK;
}

static struct {
struct arg_str *help_cmd;
struct arg_end *end;
} help_args;

static int help_command(int argc, char **argv)
{
int nerrors = arg_parse(argc, argv, (void **) &help_args);

if (nerrors != 0) {
arg_print_errors(stderr, help_args.end, argv[0]);
return 1;
}

cmd_item_t *it;
size_t len = strlen(help_args.help_cmd->sval[0]);

/* Print summary of each command */
SLIST_FOREACH(it, &s_cmd_list, next) {
if (it->help == NULL) {
continue;
}
if (len > 0 &&
(strlen(it->command) != len ||
strcmp(help_args.help_cmd->sval[0], it->command) != 0)) {
continue;
}
/* First line: command name and hint
* Pad all the hints to the same column
*/
Expand All @@ -240,6 +258,9 @@ static int help_command(int argc, char **argv)

esp_err_t esp_console_register_help_command(void)
{
help_args.help_cmd = arg_str0(NULL, NULL, "<string>", "Name of command");
help_args.end = arg_end(1);

esp_console_cmd_t command = {
.command = "help",
.help = "Print the list of registered commands",
Expand Down

0 comments on commit 25fb324

Please sign in to comment.