public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ] shared/shell: Print help info for individual commands
@ 2021-05-13  0:39 Inga Stotland
  2021-05-13  1:43 ` [BlueZ] " bluez.test.bot
  0 siblings, 1 reply; 3+ messages in thread
From: Inga Stotland @ 2021-05-13  0:39 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Inga Stotland

For menus with long list of entries, it is useful to be able invoke
help message for an individual entry to look up command description and
synopsis.
Can be invoked by entering "<command> help" or "<command> --help".
---
 src/shared/shell.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/shared/shell.c b/src/shared/shell.c
index c0de1640d..07eaa1702 100644
--- a/src/shared/shell.c
+++ b/src/shared/shell.c
@@ -352,6 +352,16 @@ static int cmd_exec(const struct bt_shell_menu_entry *entry,
 	int flags = WRDE_NOCMD;
 	bool optargs = false;
 
+	if (argc == 2 && (!memcmp(argv[1], "help", 4) ||
+				!memcmp(argv[1], "--help", 6))) {
+		printf("%s\n", entry->desc);
+		printf(COLOR_HIGHLIGHT "Usage:" COLOR_OFF "\n");
+		printf("\t %s %-*s\n", entry->cmd,
+				(int)(CMD_LENGTH - strlen(entry->cmd)),
+					!entry->arg ? "" : entry->arg);
+		return 0;
+	}
+
 	if (!entry->arg || entry->arg[0] == '\0') {
 		if (argc > 1) {
 			print_text(COLOR_HIGHLIGHT, "Too many arguments");
-- 
2.26.3


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

end of thread, other threads:[~2021-05-13 21:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-13  0:39 [PATCH BlueZ] shared/shell: Print help info for individual commands Inga Stotland
2021-05-13  1:43 ` [BlueZ] " bluez.test.bot
2021-05-13 21:10   ` Luiz Augusto von Dentz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox