From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ] shared/shell: Print commands when --help option is given
Date: Fri, 7 Sep 2018 11:18:59 +0300 [thread overview]
Message-ID: <20180907081859.19943-1-luiz.dentz@gmail.com> (raw)
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
next reply other threads:[~2018-09-07 8:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-07 8:18 Luiz Augusto von Dentz [this message]
2018-09-11 8:47 ` [PATCH BlueZ] shared/shell: Print commands when --help option is given Luiz Augusto von Dentz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180907081859.19943-1-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).