gregkh / usbutils

USB utilities for Linux, including lsusb
http://www.linux-usb.org
354 stars 199 forks source link

style: add quotation marks to vendor and product #151

Closed lunarwhite closed 2 years ago

lunarwhite commented 2 years ago

Signed-off-by: lunarwhite dwcn22@outlook.com

Description

Before:

It is confusing to use whitespace as the separator between USB vendor and product.

$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 003: ID 0e0f:0002 VMware, Inc. Virtual USB Hub
Bus 002 Device 002: ID 0e0f:0003 VMware, Inc. Virtual Mouse
Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

After:

It greatly simplifies the extraction of command output strings. If developers want to extract the vendor and product fields, then the "" will be used as a separator.

$ lsusb
Bus 001 Device 001: ID 1d6b:0002 "Linux Foundation" "2.0 root hub"
Bus 002 Device 003: ID 0e0f:0002 "VMware, Inc." "Virtual USB Hub"
Bus 002 Device 002: ID 0e0f:0003 "VMware, Inc." "Virtual Mouse"
Bus 002 Device 001: ID 1d6b:0001 "Linux Foundation" "1.1 root hub"
gregkh commented 2 years ago

This would be a break in the current output, so we can't do that as it might break existing users.

Don't rely on this output if you wish to parse this by a tool, there are better ways of getting this information in a programmatic way.

So, sorry, I can't take this.

lunarwhite commented 2 years ago

@gregkh Sorry for the bother, now I know your concern.

there are better ways of getting this information in a programmatic way.

Would you mind give me a hint about it? How to get these three human readable names: {class, vendor, product} using usbutils? Thanks in advance

gregkh commented 2 years ago

usbutils is not the tool for this, it is not designed to have the output parsed by anything else other than humans.

Use libusb, or the hw.ids database (access through systemd libraries), or just read the info directly out of /sys/ for the devices you are wanting to know.

There have been requests to make usbutils "parsable" and if it were to output something like JSON or the like, then that would be possible, but not at this point in time, sorry.