All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/2] shell: Fix not being able to auto complete submenus
@ 2022-04-07 23:59 Luiz Augusto von Dentz
  2022-04-07 23:59 ` [PATCH BlueZ 2/2] shell: Fix not able to auto complete commands with submenu prefix Luiz Augusto von Dentz
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2022-04-07 23:59 UTC (permalink / raw)
  To: linux-bluetooth

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

submenus should be part of the list of possible auto completes just as
other commands.
---
 src/shared/shell.c | 35 ++++++++++++++++++++++++++++-------
 1 file changed, 28 insertions(+), 7 deletions(-)

diff --git a/src/shared/shell.c b/src/shared/shell.c
index 7ba264b99..72232f7c0 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -139,14 +139,22 @@ static void cmd_help(int argc, char *argv[])
 	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
 }
 
-static const struct bt_shell_menu *find_menu(const char *name, size_t len)
+static const struct bt_shell_menu *find_menu(const char *name, size_t len,
+							int *index)
 {
 	const struct queue_entry *entry;
+	int i;
 
-	for (entry = queue_get_entries(data.submenus); entry;
-						entry = entry->next) {
+	for (i = 0, entry = queue_get_entries(data.submenus); entry;
+						entry = entry->next, i++) {
 		struct bt_shell_menu *menu = entry->data;
 
+		if (index) {
+			if (i < *index)
+				continue;
+			(*index)++;
+		}
+
 		if (!strncmp(menu->name, name, len))
 			return menu;
 	}
@@ -188,7 +196,7 @@ static void cmd_menu(int argc, char *argv[])
 		return bt_shell_noninteractive_quit(EXIT_FAILURE);
 	}
 
-	menu = find_menu(argv[1], strlen(argv[1]));
+	menu = find_menu(argv[1], strlen(argv[1]), NULL);
 	if (!menu) {
 		bt_shell_printf("Unable find menu with name: %s\n", argv[1]);
 		return bt_shell_noninteractive_quit(EXIT_FAILURE);
@@ -485,7 +493,7 @@ static int submenu_exec(int argc, char *argv[])
 	len = name - argv[0];
 	name[0] = '\0';
 
-	submenu = find_menu(argv[0], strlen(argv[0]));
+	submenu = find_menu(argv[0], strlen(argv[0]), NULL);
 	if (!submenu)
 		return -ENOENT;
 
@@ -735,7 +743,7 @@ static char *find_cmd(const char *text,
 static char *cmd_generator(const char *text, int state)
 {
 	static int index;
-	static bool default_menu_enabled, submenu_enabled;
+	static bool default_menu_enabled, menu_enabled, submenu_enabled;
 	static const struct bt_shell_menu *menu;
 	char *cmd;
 
@@ -754,9 +762,22 @@ static char *cmd_generator(const char *text, int state)
 			index = 0;
 			menu = data.menu;
 			default_menu_enabled = false;
+
+			if (data.main == data.menu)
+				menu_enabled = true;
 		}
 	}
 
+	if (menu_enabled) {
+		menu = find_menu(text, strlen(text), &index);
+		if (menu)
+			return strdup(menu->name);
+
+		index = 0;
+		menu = data.menu;
+		menu_enabled = false;
+	}
+
 	if (!submenu_enabled) {
 		cmd = find_cmd(text, menu->entries, &index);
 		if (cmd || menu != data.main)
@@ -766,7 +787,7 @@ static char *cmd_generator(const char *text, int state)
 		if (!cmd)
 			return NULL;
 
-		menu = find_menu(text, cmd - text);
+		menu = find_menu(text, cmd - text, NULL);
 		if (!menu)
 			return NULL;
 
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH BlueZ 2/2] shell: Fix not able to auto complete commands with submenu prefix
  2022-04-07 23:59 [PATCH BlueZ 1/2] shell: Fix not being able to auto complete submenus Luiz Augusto von Dentz
@ 2022-04-07 23:59 ` Luiz Augusto von Dentz
  2022-04-08  3:33 ` [BlueZ,1/2] shell: Fix not being able to auto complete submenus bluez.test.bot
  2022-04-11 18:20 ` [PATCH BlueZ 1/2] " patchwork-bot+bluetooth
  2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2022-04-07 23:59 UTC (permalink / raw)
  To: linux-bluetooth

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

If the command was given with submenu prefix the code wasn't able to
detect the command to be able to generate the auto complete for its
arguments.
---
 src/shared/shell.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/src/shared/shell.c b/src/shared/shell.c
index 72232f7c0..dfda8128a 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -911,6 +911,26 @@ static char **menu_completion(const struct bt_shell_menu_entry *entry,
 	return matches;
 }
 
+static char **submenu_completion(const char *text, int argc, char *input_cmd)
+{
+	const struct bt_shell_menu *menu;
+	char *cmd;
+
+	if (data.main != data.menu)
+		return NULL;
+
+	cmd = strrchr(input_cmd, '.');
+	if (!cmd)
+		return NULL;
+
+	menu = find_menu(input_cmd, cmd - input_cmd, NULL);
+	if (!menu)
+		return NULL;
+
+	return menu_completion(menu->entries, text, argc,
+				input_cmd + strlen(menu->name) + 1);
+}
+
 static char **shell_completion(const char *text, int start, int end)
 {
 	char **matches = NULL;
@@ -928,10 +948,14 @@ static char **shell_completion(const char *text, int start, int end)
 
 		matches = menu_completion(default_menu, text, w.we_wordc,
 							w.we_wordv[0]);
-		if (!matches)
+		if (!matches) {
 			matches = menu_completion(data.menu->entries, text,
 							w.we_wordc,
 							w.we_wordv[0]);
+			if (!matches)
+				matches = submenu_completion(text, w.we_wordc,
+								w.we_wordv[0]);
+		}
 
 		wordfree(&w);
 	} else {
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [BlueZ,1/2] shell: Fix not being able to auto complete submenus
  2022-04-07 23:59 [PATCH BlueZ 1/2] shell: Fix not being able to auto complete submenus Luiz Augusto von Dentz
  2022-04-07 23:59 ` [PATCH BlueZ 2/2] shell: Fix not able to auto complete commands with submenu prefix Luiz Augusto von Dentz
@ 2022-04-08  3:33 ` bluez.test.bot
  2022-04-11 18:20 ` [PATCH BlueZ 1/2] " patchwork-bot+bluetooth
  2 siblings, 0 replies; 4+ messages in thread
From: bluez.test.bot @ 2022-04-08  3:33 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz

[-- Attachment #1: Type: text/plain, Size: 998 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=630223

---Test result---

Test Summary:
CheckPatch                    PASS      2.86 seconds
GitLint                       PASS      1.92 seconds
Prep - Setup ELL              PASS      42.50 seconds
Build - Prep                  PASS      0.67 seconds
Build - Configure             PASS      8.50 seconds
Build - Make                  PASS      1238.33 seconds
Make Check                    PASS      11.68 seconds
Make Check w/Valgrind         PASS      437.83 seconds
Make Distcheck                PASS      225.68 seconds
Build w/ext ELL - Configure   PASS      8.59 seconds
Build w/ext ELL - Make        PASS      1239.81 seconds
Incremental Build with patchesPASS      2536.87 seconds



---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH BlueZ 1/2] shell: Fix not being able to auto complete submenus
  2022-04-07 23:59 [PATCH BlueZ 1/2] shell: Fix not being able to auto complete submenus Luiz Augusto von Dentz
  2022-04-07 23:59 ` [PATCH BlueZ 2/2] shell: Fix not able to auto complete commands with submenu prefix Luiz Augusto von Dentz
  2022-04-08  3:33 ` [BlueZ,1/2] shell: Fix not being able to auto complete submenus bluez.test.bot
@ 2022-04-11 18:20 ` patchwork-bot+bluetooth
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+bluetooth @ 2022-04-11 18:20 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth

Hello:

This series was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Thu,  7 Apr 2022 16:59:48 -0700 you wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> 
> submenus should be part of the list of possible auto completes just as
> other commands.
> ---
>  src/shared/shell.c | 35 ++++++++++++++++++++++++++++-------
>  1 file changed, 28 insertions(+), 7 deletions(-)

Here is the summary with links:
  - [BlueZ,1/2] shell: Fix not being able to auto complete submenus
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=f547db04fdc6
  - [BlueZ,2/2] shell: Fix not able to auto complete commands with submenu prefix
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=195d9b80e1a9

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-04-11 18:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-07 23:59 [PATCH BlueZ 1/2] shell: Fix not being able to auto complete submenus Luiz Augusto von Dentz
2022-04-07 23:59 ` [PATCH BlueZ 2/2] shell: Fix not able to auto complete commands with submenu prefix Luiz Augusto von Dentz
2022-04-08  3:33 ` [BlueZ,1/2] shell: Fix not being able to auto complete submenus bluez.test.bot
2022-04-11 18:20 ` [PATCH BlueZ 1/2] " patchwork-bot+bluetooth

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.