From 4bc2a2231729753f93130bad49bad273e9f7d9dd Mon Sep 17 00:00:00 2001 From: Inga Stotland Date: Wed, 12 May 2021 17:39:09 -0700 Subject: [PATCH] shared/shell: Print help info for individual commands For menus with long list of entries, it is useful to be able invoke help message for an individual entry to look up command description and synopsis. Can be invoked by entering " help" or " --help". --- src/shared/shell.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/shared/shell.c b/src/shared/shell.c index c0de1640d..07eaa1702 100644 --- a/src/shared/shell.c +++ b/src/shared/shell.c @@ -352,6 +352,16 @@ static int cmd_exec(const struct bt_shell_menu_entry *entry, int flags = WRDE_NOCMD; bool optargs = false; + if (argc == 2 && (!memcmp(argv[1], "help", 4) || + !memcmp(argv[1], "--help", 6))) { + printf("%s\n", entry->desc); + printf(COLOR_HIGHLIGHT "Usage:" COLOR_OFF "\n"); + printf("\t %s %-*s\n", entry->cmd, + (int)(CMD_LENGTH - strlen(entry->cmd)), + !entry->arg ? "" : entry->arg); + return 0; + } + if (!entry->arg || entry->arg[0] == '\0') { if (argc > 1) { print_text(COLOR_HIGHLIGHT, "Too many arguments"); -- 2.47.3