From 25fb324f951bab14f799fa88f331bb4a865b041d Mon Sep 17 00:00:00 2001 From: Josef Norgan Date: Mon, 24 Jul 2023 15:29:10 -0700 Subject: [PATCH] Added Help command parameter for displaying only a specific command --- components/console/commands.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/components/console/commands.c b/components/console/commands.c index 77654a30c2fe..4f220a0e822c 100644 --- a/components/console/commands.c +++ b/components/console/commands.c @@ -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 */ @@ -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, "", "Name of command"); + help_args.end = arg_end(1); + esp_console_cmd_t command = { .command = "help", .help = "Print the list of registered commands",