Skip to content

Commit

Permalink
Add interactive flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jneem committed Nov 4, 2023
1 parent 39fbdac commit f62a1e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions espflash/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ pub struct ConnectArgs {
/// Serial port connected to target device
#[arg(short = 'p', long, env = "ESPFLASH_PORT")]
pub port: Option<String>,
/// Require confirmation before auto-connecting to a recognized device.
#[arg(short = 'i', long)]
pub interactive: bool,
/// DTR pin to use for the internal UART hardware. Uses BCM numbering.
#[cfg(feature = "raspberry")]
#[cfg_attr(feature = "raspberry", clap(long))]
Expand Down
11 changes: 8 additions & 3 deletions espflash/src/cli/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub fn get_serial_port_info(
} else if let Some(serial) = &config.connection.serial {
find_serial_port(&ports, serial)
} else {
let (port, matches) = select_serial_port(ports, config)?;
let (port, matches) = select_serial_port(ports, config, matches.interactive)?;

match &port.port_type {
SerialPortType::UsbPort(usb_info) if !matches => {
Expand Down Expand Up @@ -202,6 +202,7 @@ const KNOWN_DEVICES: &[UsbDevice] = &[
fn select_serial_port(
mut ports: Vec<SerialPortInfo>,
config: &Config,
force_interactive: bool,
) -> Result<(SerialPortInfo, bool), Error> {
// Does this port match a known one?
let matches = |port: &SerialPortInfo| match &port.port_type {
Expand All @@ -220,8 +221,12 @@ fn select_serial_port(
.as_slice()
{
// There is a unique recognized device.
Ok(((*port).to_owned(), true))
} else if ports.len() > 1 {
if !force_interactive {
return Ok(((*port).to_owned(), true));
}
}

if ports.len() > 1 {
// Multiple serial ports detected.
info!("Detected {} serial ports", ports.len());
info!("Ports which match a known common dev board are highlighted");
Expand Down

0 comments on commit f62a1e5

Please sign in to comment.