From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v2 3/3] commands: drvinfo: support filtering by driver
Date: Thu, 9 Nov 2023 13:25:51 +0100 [thread overview]
Message-ID: <20231109122551.1486020-3-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20231109122551.1486020-1-a.fatoum@pengutronix.de>
drvinfo can be very long especially for the in-tree defconfigs.
Make it more convenient to use by add optional filtering support:
barebox@board:/ drvinfo '*imx7d*'
Driver Device(s)
--------------------
imx7d-src
30390000.reset-controller@30390000.of
imx7d_adc
30610000.adc@30610000.of
30620000.adc@30620000.of
Use 'devinfo DEVICE' for more information
Furthermore, tab completion for driver names is now supported as well.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
- use fnmatch to support glob patterns for driver names (Sascha)
- add functional autocomplete despite spaces (Sascha)
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
commands/drvinfo.c | 8 ++++++++
common/complete.c | 15 +++++++++++++++
include/complete.h | 1 +
3 files changed, 24 insertions(+)
diff --git a/commands/drvinfo.c b/commands/drvinfo.c
index b984b9472585..e13b04870ee4 100644
--- a/commands/drvinfo.c
+++ b/commands/drvinfo.c
@@ -5,15 +5,21 @@
#include <common.h>
#include <command.h>
#include <driver.h>
+#include <complete.h>
+#include <fnmatch.h>
static int do_drvinfo(int argc, char *argv[])
{
+ char *pattern = argv[1];
struct driver *drv;
struct device *dev;
printf("Driver\tDevice(s)\n");
printf("--------------------\n");
for_each_driver(drv) {
+ if (pattern && fnmatch(pattern, drv->name, 0))
+ continue;
+
printf("%s\n",drv->name);
for_each_device(dev) {
if (dev->driver == drv)
@@ -31,5 +37,7 @@ static int do_drvinfo(int argc, char *argv[])
BAREBOX_CMD_START(drvinfo)
.cmd = do_drvinfo,
BAREBOX_CMD_DESC("list compiled-in device drivers")
+ BAREBOX_CMD_OPTS("[DRIVER]")
BAREBOX_CMD_GROUP(CMD_GRP_INFO)
+ BAREBOX_CMD_COMPLETE(driver_complete)
BAREBOX_CMD_END
diff --git a/common/complete.c b/common/complete.c
index ef31a36faf5f..3911535621b1 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -186,6 +186,21 @@ static int device_param_complete(struct device *dev, const char *devname,
return 0;
}
+int driver_complete(struct string_list *sl, char *instr)
+{
+ struct driver_d *drv;
+
+ for_each_driver(drv) {
+ if (!strstarts_escaped(drv->name, instr))
+ continue;
+
+ string_list_add_asprintf(sl, "%s ", drv->name);
+ }
+
+ return COMPLETE_CONTINUE;
+}
+EXPORT_SYMBOL(driver_complete);
+
int empty_complete(struct string_list *sl, char *instr)
{
return COMPLETE_END;
diff --git a/include/complete.h b/include/complete.h
index b0e675b5599f..2068760ac235 100644
--- a/include/complete.h
+++ b/include/complete.h
@@ -14,6 +14,7 @@ void complete_reset(void);
int command_complete(struct string_list *sl, char *instr);
int device_complete(struct string_list *sl, char *instr);
+int driver_complete(struct string_list *sl, char *instr);
int empty_complete(struct string_list *sl, char *instr);
int eth_complete(struct string_list *sl, char *instr);
int command_var_complete(struct string_list *sl, char *instr);
--
2.39.2
next prev parent reply other threads:[~2023-11-09 12:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-09 12:25 [PATCH v2 1/3] glob: drop needless ifdeffery in {glob,fnmatch}.h Ahmad Fatoum
2023-11-09 12:25 ` [PATCH v2 2/3] complete: add support for spaces in completions Ahmad Fatoum
2023-11-09 12:25 ` Ahmad Fatoum [this message]
2023-11-13 12:51 ` [PATCH v2 1/3] glob: drop needless ifdeffery in {glob,fnmatch}.h Sascha Hauer
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=20231109122551.1486020-3-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.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