From f317cc55f2a012d4219d21cafea78a7f0008f6e3 Mon Sep 17 00:00:00 2001 From: Josef Norgan Date: Mon, 24 Jul 2023 15:29:10 -0700 Subject: [PATCH] feat(esp_console): Added Help command parameter for displaying only specific command --- components/console/commands.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/components/console/commands.c b/components/console/commands.c index 75ab29e90d..e7abf297cd 100644 --- a/components/console/commands.c +++ b/components/console/commands.c @@ -215,8 +215,20 @@ 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; /* Print summary of each command */ @@ -224,6 +236,10 @@ static int help_command(int argc, char **argv) if (it->help == NULL) { continue; } + if (strlen(help_args.help_cmd->sval[0]) > 0 && + 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 */ @@ -246,10 +262,14 @@ 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", - .func = &help_command + .func = &help_command, + .argtable = &help_args }; return esp_console_cmd_register(&command); }