From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 4/4] shared/shell: Add default argument generator
Date: Sun, 26 Nov 2017 22:21:26 +0200 [thread overview]
Message-ID: <20171126202126.27783-4-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20171126202126.27783-1-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
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
next prev parent reply other threads:[~2017-11-26 20:21 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-26 20:21 [PATCH BlueZ 1/4] shared/shell: Detect if the arguments are properly set Luiz Augusto von Dentz
2017-11-26 20:21 ` [PATCH BlueZ 2/4] client: Remove argument checks Luiz Augusto von Dentz
2017-11-26 20:21 ` [PATCH BlueZ 3/4] client: Fix format of arguments of set-service and set-manufacturer Luiz Augusto von Dentz
2017-11-26 20:21 ` Luiz Augusto von Dentz [this message]
2017-11-27 4:17 ` [PATCH BlueZ 4/4] shared/shell: Add default argument generator ERAMOTO Masaya
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=20171126202126.27783-4-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).