Diff between 5d24fe74da58489962e391cd316476838f4ce641 and 1c3282e1e00c7934f099d2ea7cf15c0e29d079b0

Changed Files

File Additions Deletions Status
src/shared/shell.c +14 -0 modified
src/shared/shell.h +1 -0 modified

Full Patch

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 @@ 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 10747c9..33c31f3 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);