shared/shell: Add bt_shell_usage
bt_shell_usage can be used to print the usage of the current command
in execution.
diff --git a/src/shared/shell.c b/src/shared/shell.c
index de73299..b9563ea 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -76,6 +76,7 @@
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 @@
wordfree(&w);
exec:
+ data.exec = entry;
+
if (entry->func)
entry->func(argc, argv);
+ data.exec = NULL;
+
return 0;
fail:
@@ -464,6 +469,15 @@
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 10747c9..33c31f3 100644
--- a/src/shared/shell.h
+++ b/src/shared/shell.h
@@ -82,6 +82,7 @@
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);