From 1c3282e1e00c7934f099d2ea7cf15c0e29d079b0 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 26 Feb 2018 16:37:29 +0200 Subject: [PATCH] shared/shell: Add bt_shell_usage bt_shell_usage can be used to print the usage of the current command in execution. --- src/shared/shell.c | 14 ++++++++++++++ src/shared/shell.h | 1 + 2 files changed, 15 insertions(+) diff --git a/src/shared/shell.c b/src/shared/shell.c index de73299a1..b9563ea76 100644 --- a/src/shared/shell.c +++ b/src/shared/shell.c @@ -76,6 +76,7 @@ static struct { const struct bt_shell_menu *menu; const struct bt_shell_menu *main; struct queue *submenus; + const struct bt_shell_menu_entry *exec; struct queue *envs; } data; @@ -331,9 +332,13 @@ optional: wordfree(&w); exec: + data.exec = entry; + if (entry->func) entry->func(argc, argv); + data.exec = NULL; + return 0; fail: @@ -464,6 +469,15 @@ void bt_shell_hexdump(const unsigned char *buf, size_t len) util_hexdump(' ', buf, len, print_string, NULL); } +void bt_shell_usage() +{ + if (!data.exec) + return; + + bt_shell_printf("Usage: %s %s\n", data.exec->cmd, + data.exec->arg ? data.exec->arg : ""); +} + void bt_shell_prompt_input(const char *label, const char *msg, bt_shell_prompt_input_func func, void *user_data) { diff --git a/src/shared/shell.h b/src/shared/shell.h index 10747c955..33c31f35b 100644 --- a/src/shared/shell.h +++ b/src/shared/shell.h @@ -82,6 +82,7 @@ void bt_shell_set_prompt(const char *string); void bt_shell_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2))); void bt_shell_hexdump(const unsigned char *buf, size_t len); +void bt_shell_usage(void); void bt_shell_prompt_input(const char *label, const char *msg, bt_shell_prompt_input_func func, void *user_data); -- 2.47.3