[PATCH BlueZ 4/4] shared/shell: Add default argument generator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Luiz Augusto von Dentz <luiz.von.dentz@xxxxxxxxx>

This adds a default argument generator if the command don't provide
one, the generator will print out the argument list so the user don't
have to always resort to help for checking it.
---
 src/shared/shell.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/shared/shell.c b/src/shared/shell.c
index 73aedaf79..d0cd2e6fe 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -518,6 +518,17 @@ static char *cmd_generator(const char *text, int state)
 	return find_cmd(text, data.menu->entries, &index);
 }
 
+static char *arg_generator(const char *text, int state)
+{
+	if (!text)
+		return NULL;
+
+	if (!state)
+		return strdup(text);
+
+	return NULL;
+}
+
 static char **menu_completion(const struct bt_shell_menu_entry *entry,
 				const char *text, char *input_cmd)
 {
@@ -527,8 +538,12 @@ static char **menu_completion(const struct bt_shell_menu_entry *entry,
 		if (strcmp(entry->cmd, input_cmd))
 			continue;
 
-		if (!entry->gen)
-			continue;
+		if (!entry->gen) {
+			rl_completion_display_matches_hook = NULL;
+			matches = rl_completion_matches(entry->arg,
+							arg_generator);
+			break;
+		}
 
 		rl_completion_display_matches_hook = entry->disp;
 		matches = rl_completion_matches(text, entry->gen);
-- 
2.13.6

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux