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@xxxxxxxxxxx imx7d_adc 30610000.adc@xxxxxxxxxxx 30620000.adc@xxxxxxxxxxx Use 'devinfo DEVICE' for more information Furthermore, tab completion for driver names is now supported as well. Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx> --- 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@xxxxxxxxxxxxxx> --- 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