[PATCH 5/6] commands: drvinfo: support filtering by driver
Ahmad Fatoum
a.fatoum at pengutronix.de
Tue Oct 25 23:42:04 PDT 2022
drvinfo can be very long especially for the in-tree defconfigs,
add optional filtering support:
barebox at board:/ drvinfo imx7d
Driver Device(s)
--------------------
imx7d-src
30390000.reset-controller at 30390000.of
imx7d_adc
30610000.adc at 30610000.of
30620000.adc at 30620000.of
Use 'devinfo DEVICE' for more information
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
commands/drvinfo.c | 13 +++++++++++++
common/complete.c | 21 +++++++++++++++++++++
include/complete.h | 1 +
3 files changed, 35 insertions(+)
diff --git a/commands/drvinfo.c b/commands/drvinfo.c
index 9f8f971ee9dd..27ff55f01d90 100644
--- a/commands/drvinfo.c
+++ b/commands/drvinfo.c
@@ -5,15 +5,23 @@
#include <common.h>
#include <command.h>
#include <driver.h>
+#include <complete.h>
static int do_drvinfo(int argc, char *argv[])
{
+ char *filter = NULL;
struct driver_d *drv;
struct device_d *dev;
+ if (IS_ENABLED(CONFIG_AUTO_COMPLETE) && argc > 1)
+ filter = strjoin(" ", &argv[1], argc - 1);
+
printf("Driver\tDevice(s)\n");
printf("--------------------\n");
for_each_driver(drv) {
+ if (filter && !str_has_prefix(drv->name, filter))
+ continue;
+
printf("%s\n",drv->name);
for_each_device(dev) {
if (dev->driver == drv)
@@ -24,6 +32,7 @@ static int do_drvinfo(int argc, char *argv[])
if (IS_ENABLED(CONFIG_CMD_DEVINFO))
printf("\nUse 'devinfo DEVICE' for more information\n");
+ free(filter);
return 0;
}
@@ -31,5 +40,9 @@ static int do_drvinfo(int argc, char *argv[])
BAREBOX_CMD_START(drvinfo)
.cmd = do_drvinfo,
BAREBOX_CMD_DESC("list compiled-in device drivers")
+#ifdef CONFIG_AUTO_COMPLETE
+ BAREBOX_CMD_OPTS("[DRIVER]")
+#endif
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 ab3c98549314..916d13d776ce 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -174,6 +174,27 @@ static int device_param_complete(struct device_d *dev, struct string_list *sl,
return 0;
}
+int driver_complete(struct string_list *sl, char *instr)
+{
+ struct driver_d *drv;
+ int len;
+
+ if (!instr)
+ instr = "";
+
+ len = strlen(instr);
+
+ for_each_driver(drv) {
+ if (strncmp(instr, drv->name, len))
+ 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.30.2
More information about the barebox
mailing list