@@ -33,7 +33,7 @@ pub fn get_serial_port_info(
3333 // doesn't work (on Windows) with "dummy" device paths like `COM4`. That's
3434 // the reason we need to handle Windows/Posix differently.
3535
36- let ports = detect_usb_serial_ports ( ) . unwrap_or_default ( ) ;
36+ let ports = detect_usb_serial_ports ( matches . list_all_ports ) . unwrap_or_default ( ) ;
3737
3838 if let Some ( serial) = & matches. port {
3939 find_serial_port ( & ports, serial)
@@ -108,7 +108,7 @@ fn find_serial_port(ports: &[SerialPortInfo], name: &str) -> Result<SerialPortIn
108108/// Linux we can do some manual parsing of sysfs to get the relevant bits
109109/// without udev
110110#[ cfg( all( target_os = "linux" , target_env = "musl" ) ) ]
111- fn detect_usb_serial_ports ( ) -> Result < Vec < SerialPortInfo > > {
111+ fn detect_usb_serial_ports ( _list_all_ports : bool ) -> Result < Vec < SerialPortInfo > > {
112112 use std:: {
113113 fs:: { read_link, read_to_string} ,
114114 path:: PathBuf ,
@@ -166,20 +166,24 @@ fn detect_usb_serial_ports() -> Result<Vec<SerialPortInfo>> {
166166
167167/// Returns a vector with available USB serial ports.
168168#[ cfg( not( all( target_os = "linux" , target_env = "musl" ) ) ) ]
169- fn detect_usb_serial_ports ( ) -> Result < Vec < SerialPortInfo > > {
169+ fn detect_usb_serial_ports ( list_all_ports : bool ) -> Result < Vec < SerialPortInfo > > {
170170 let ports = available_ports ( ) . into_diagnostic ( ) ?;
171171 let ports = ports
172172 . into_iter ( )
173173 . filter ( |port_info| {
174- matches ! (
175- & port_info. port_type,
176- SerialPortType :: UsbPort ( ..) |
177- // Allow PciPort. The user may want to use it.
178- // The port might have been misdetected by the system as PCI.
179- SerialPortType :: PciPort |
180- // Good luck.
181- SerialPortType :: Unknown
182- )
174+ if list_all_ports {
175+ matches ! (
176+ & port_info. port_type,
177+ SerialPortType :: UsbPort ( ..) |
178+ // Allow PciPort. The user may want to use it.
179+ // The port might have been misdetected by the system as PCI.
180+ SerialPortType :: PciPort |
181+ // Good luck.
182+ SerialPortType :: Unknown
183+ )
184+ } else {
185+ matches ! ( & port_info. port_type, SerialPortType :: UsbPort ( ..) )
186+ }
183187 } )
184188 . collect :: < Vec < _ > > ( ) ;
185189
0 commit comments