Diff between a38796b18d8374e92907e620e347285943061009 and c84fcfff3c77c0bfe21b6777ba28fa085295cebc

Changed Files

File Additions Deletions Status
src/shared/shell.c +49 -5 modified

Full Patch

diff --git a/src/shared/shell.c b/src/shared/shell.c
index 53f5136..9b01255 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -61,6 +61,8 @@ struct bt_shell_env {
 	void *value;
 };
 
+static char *cmplt = "help";
+
 static struct {
 	bool init;
 	char *name;
@@ -97,9 +99,41 @@ static void cmd_quit(int argc, char *argv[])
 	mainloop_quit();
 }
 
+static void print_cmds(void)
+{
+	const struct bt_shell_menu_entry *entry;
+	const struct queue_entry *submenu;
+
+	if (!data.menu)
+		return;
+
+	printf("Commands:\n");
+
+	for (entry = data.menu->entries; entry->cmd; entry++) {
+		printf("\t%s%s\t%s\n", entry->cmd,
+			strlen(entry->cmd) < 8 ? "\t" : "", entry->desc);
+	}
+
+	for (submenu = queue_get_entries(data.submenus); submenu;
+					submenu = submenu->next) {
+		struct bt_shell_menu *menu = submenu->data;
+
+		printf("\n\t%s.:\n", menu->name);
+
+		for (entry = menu->entries; entry->cmd; entry++) {
+			printf("\t\t%s%s\t%s\n", entry->cmd,
+				strlen(entry->cmd) < 8 ? "\t" : "",
+				entry->desc);
+		}
+	}
+}
+
 static void cmd_help(int argc, char *argv[])
 {
-	shell_print_menu();
+	if (argv[0] == cmplt)
+		print_cmds();
+	else
+		shell_print_menu();
 
 	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
 }
@@ -955,11 +989,18 @@ static const struct option main_options[] = {
 
 static void usage(int argc, char **argv, const struct bt_shell_opt *opt)
 {
+	const char *name;
 	unsigned int i;
 
-	printf("%s ver %s\n", argv[0], VERSION);
+	name = strrchr(argv[0], '/');
+	if (!name)
+		name = argv[0];
+	else
+		name++;
+
+	printf("%s ver %s\n", name, VERSION);
 	printf("Usage:\n"
-		"\t%s [options]\n", argv[0]);
+		"\t%s [--options] [commands]\n", name);
 
 	printf("Options:\n");
 
@@ -997,8 +1038,10 @@ void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt)
 			return;
 		case 'h':
 			usage(argc, argv, opt);
-			exit(EXIT_SUCCESS);
-			return;
+			data.argc = 1;
+			data.argv = &cmplt;
+			data.mode = 1;
+			goto done;
 		case 't':
 			data.timeout = atoi(optarg);
 			break;
@@ -1030,6 +1073,7 @@ void bt_shell_init(int argc, char **argv, const struct bt_shell_opt *opt)
 	optind = 0;
 	data.mode = (data.argc > 0);
 
+done:
 	if (data.mode)
 		bt_shell_set_env("NON_INTERACTIVE", &data.mode);