Skip to content

Commit

Permalink
lsusb: fix backwards VID:PID output (#480)
Browse files Browse the repository at this point in the history
I just lost a kind of embarassing amount of time to the fact that
`humility lsusb` _claims_ to print USB devices in the format
`VID:PID:SERIAL`, but actually outputs `PID:VID:SERIAL`. To spare others
from the suffering this caused me, this commit changes the command to
actually print what it says it does.

I chose to bring the output in line with the help text, rather than the
other way around, because the help text's format is the same format used
by the `--probe` CLI flag and the `environment.json` file format, and
using `PID:VID:SERIAL` with `--probe` or in the config file will make
Humility unhappy.

Fixes #479
  • Loading branch information
hawkw authored Apr 18, 2024
1 parent e94bc0d commit c0888b0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cmd/lsusb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn list1(dev: &rusb::Device<impl rusb::UsbContext>) -> Result<String> {
let handle = match dev.open() {
Ok(handle) => handle,
Err(e) => {
return Err(anyhow!("{pid:04x}:{vid:04x}:???\topen failed: {e}"));
return Err(anyhow!("{vid:04x}:{pid:04x}:???\topen failed: {e}"));
}
};
let lang = *handle
Expand All @@ -99,7 +99,7 @@ fn list1(dev: &rusb::Device<impl rusb::UsbContext>) -> Result<String> {
.read_serial_number_string(lang, &desc, TIMEOUT)
.unwrap_or_else(|_| "(serial unknown)".to_string());

Ok(format!("{pid:04x}:{vid:04x}:{serial}\t{man}\t{prod}"))
Ok(format!("{vid:04x}:{pid:04x}:{serial}\t{man}\t{prod}"))
}

pub fn init() -> Command {
Expand Down

0 comments on commit c0888b0

Please sign in to comment.