@@ -33,7 +33,7 @@ pub fn get_serial_port_info(
33
33
// doesn't work (on Windows) with "dummy" device paths like `COM4`. That's
34
34
// the reason we need to handle Windows/Posix differently.
35
35
36
- let ports = detect_usb_serial_ports ( ) . unwrap_or_default ( ) ;
36
+ let ports = detect_usb_serial_ports ( matches . list_all_ports ) . unwrap_or_default ( ) ;
37
37
38
38
if let Some ( serial) = & matches. port {
39
39
find_serial_port ( & ports, serial)
@@ -108,7 +108,7 @@ fn find_serial_port(ports: &[SerialPortInfo], name: &str) -> Result<SerialPortIn
108
108
/// Linux we can do some manual parsing of sysfs to get the relevant bits
109
109
/// without udev
110
110
#[ 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 > > {
112
112
use std:: {
113
113
fs:: { read_link, read_to_string} ,
114
114
path:: PathBuf ,
@@ -166,20 +166,24 @@ fn detect_usb_serial_ports() -> Result<Vec<SerialPortInfo>> {
166
166
167
167
/// Returns a vector with available USB serial ports.
168
168
#[ 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 > > {
170
170
let ports = available_ports ( ) . into_diagnostic ( ) ?;
171
171
let ports = ports
172
172
. into_iter ( )
173
173
. 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
+ }
183
187
} )
184
188
. collect :: < Vec < _ > > ( ) ;
185
189
0 commit comments