linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ] shared/shell: Print commands when --help option is given
@ 2018-09-07  8:18 Luiz Augusto von Dentz
  2018-09-11  8:47 ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 2+ messages in thread
From: Luiz Augusto von Dentz @ 2018-09-07  8:18 UTC (permalink / raw)
  To: linux-bluetooth

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

This enables the user to see what command could be given in the
non-interactive mode e.g:

> bluetooth-player --help
bluetooth-player ver 5.50
Usage:
	bluetooth-player [--options] [commands]
Options:
	--timeout 	Timeout in seconds for non-interactive mode
	--version 	Display version
	--help 		Display help
Commands:
	list		List available players
	show		Player information
	select		Select default player
	play		Start playback
	pause		Pause playback
	stop		Stop playback
	next		Jump to next item
	previous	Jump to previous item
	fast-forward	Fast forward playback
	rewind		Rewind playback
	equalizer	Enable/Disable equalizer
	repeat		Set repeat mode
	shuffle		Set shuffle mode
	scan		Set scan mode
	change-folder	Change current folder
	list-items	List items of current folder
	search		Search items containing string
	queue		Add item to playlist queue
	show-item	Show item information
---
 src/shared/shell.c | 54 +++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 49 insertions(+), 5 deletions(-)

diff --git a/src/shared/shell.c b/src/shared/shell.c
index 53f513613..9b0125579 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);
 
-- 
2.17.1

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

* Re: [PATCH BlueZ] shared/shell: Print commands when --help option is given
  2018-09-07  8:18 [PATCH BlueZ] shared/shell: Print commands when --help option is given Luiz Augusto von Dentz
@ 2018-09-11  8:47 ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 2+ messages in thread
From: Luiz Augusto von Dentz @ 2018-09-11  8:47 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

On Fri, Sep 7, 2018 at 11:18 AM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> This enables the user to see what command could be given in the
> non-interactive mode e.g:
>
>> bluetooth-player --help
> bluetooth-player ver 5.50
> Usage:
>         bluetooth-player [--options] [commands]
> Options:
>         --timeout       Timeout in seconds for non-interactive mode
>         --version       Display version
>         --help          Display help
> Commands:
>         list            List available players
>         show            Player information
>         select          Select default player
>         play            Start playback
>         pause           Pause playback
>         stop            Stop playback
>         next            Jump to next item
>         previous        Jump to previous item
>         fast-forward    Fast forward playback
>         rewind          Rewind playback
>         equalizer       Enable/Disable equalizer
>         repeat          Set repeat mode
>         shuffle         Set shuffle mode
>         scan            Set scan mode
>         change-folder   Change current folder
>         list-items      List items of current folder
>         search          Search items containing string
>         queue           Add item to playlist queue
>         show-item       Show item information
> ---
>  src/shared/shell.c | 54 +++++++++++++++++++++++++++++++++++++++++-----
>  1 file changed, 49 insertions(+), 5 deletions(-)
>
> diff --git a/src/shared/shell.c b/src/shared/shell.c
> index 53f513613..9b0125579 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);
>
> --
> 2.17.1

Applied.


-- 
Luiz Augusto von Dentz

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

end of thread, other threads:[~2018-09-11  8:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-07  8:18 [PATCH BlueZ] shared/shell: Print commands when --help option is given Luiz Augusto von Dentz
2018-09-11  8:47 ` 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;
as well as URLs for NNTP newsgroup(s).