From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: Sascha Hauer <sha@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH 5/6] commands: drvinfo: support filtering by driver
Date: Thu, 27 Oct 2022 09:51:38 +0200 [thread overview]
Message-ID: <85fd321f-b525-76a2-1184-39a0ac2f9caa@pengutronix.de> (raw)
In-Reply-To: <20221027072916.GB9130@pengutronix.de>
Hi!
On 27.10.22 09:29, Sascha Hauer wrote:
> On Wed, Oct 26, 2022 at 08:42:04AM +0200, Ahmad Fatoum wrote:
>> drvinfo can be very long especially for the in-tree defconfigs,
>> add optional filtering support:
>> + if (IS_ENABLED(CONFIG_AUTO_COMPLETE) && argc > 1)
>> + filter = strjoin(" ", &argv[1], argc - 1);
>
> Why does this depend on CONFIG_AUTO_COMPLETE?
drvinfo is something I think should always be enabled and I didn't want
to bloat it unconditionally.
>
>> +
>> printf("Driver\tDevice(s)\n");
>> printf("--------------------\n");
>> for_each_driver(drv) {
>> + if (filter && !str_has_prefix(drv->name, filter))
>> + continue;
>
> I don't see how this is expected to work. When you pass multiple drivers
> as argument 'filter' will be a concatenation of multiple driver names
> which then matches nothing.
Autocomplete doesn't work for elements with spaces, so when you write
drvinfo TI<Tab>
You get
drvinfo TI DP83
with no further ability to complete. The prefix matching can work with that
and will produce:
Driver Device(s)
--------------------
TI DP83867
TI DP83TD510E
Use 'devinfo DEVICE' for more information
> How about using fnmatch? We could then pass things like "*usb*"
I am content with the tab completion.
Cheers,
Ahmad
>
> Sascha
>
>
>> +
>> 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
>>
>>
>>
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
next prev parent reply other threads:[~2022-10-27 7:53 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-26 6:42 [PATCH 1/6] commands: add new uptime command Ahmad Fatoum
2022-10-26 6:42 ` [PATCH 2/6] commands: time: refactor into new strjoin Ahmad Fatoum
2022-10-26 6:42 ` [PATCH 3/6] string: reduce strjoin runtime, drop trailing separator Ahmad Fatoum
2022-10-27 6:56 ` Sascha Hauer
2022-10-27 7:24 ` Ahmad Fatoum
2022-10-27 7:33 ` Sascha Hauer
2022-10-27 7:53 ` Ahmad Fatoum
2022-10-26 6:42 ` [PATCH 4/6] test: self: add strjoin tests Ahmad Fatoum
2022-10-26 6:42 ` [PATCH 5/6] commands: drvinfo: support filtering by driver Ahmad Fatoum
2022-10-27 7:29 ` Sascha Hauer
2022-10-27 7:51 ` Ahmad Fatoum [this message]
2022-10-27 8:49 ` Sascha Hauer
2022-10-26 6:42 ` [PATCH 6/6] test: self: only include ramfs selftest when CONFIG_SELFTEST_FS_RAMFS=y Ahmad Fatoum
2022-10-27 7:11 ` [PATCH 1/6] commands: add new uptime command 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=85fd321f-b525-76a2-1184-39a0ac2f9caa@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=sha@pengutronix.de \
/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