From 30512415122a0566cbb30e1ce38eb621ecf3387c Mon Sep 17 00:00:00 2001 From: jneem Date: Tue, 7 Nov 2023 02:06:50 -0600 Subject: [PATCH] Add interactive flag (#455) * Add interactive flag * Make it confirm-port * Add changelog entry --- CHANGELOG.md | 1 + espflash/src/cli/mod.rs | 3 +++ espflash/src/cli/serial.rs | 11 ++++++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85e23248..2968b8c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Read esp-println generated defmt messages (#466) - Add --target-app-partition argument to flash command (#461) +- Add --confirm-port argument to flash command (#455) ### Fixed diff --git a/espflash/src/cli/mod.rs b/espflash/src/cli/mod.rs index c3912c16..bca8ddf0 100644 --- a/espflash/src/cli/mod.rs +++ b/espflash/src/cli/mod.rs @@ -52,6 +52,9 @@ pub struct ConnectArgs { /// Serial port connected to target device #[arg(short = 'p', long, env = "ESPFLASH_PORT")] pub port: Option, + /// Require confirmation before auto-connecting to a recognized device. + #[arg(short = 'c', long)] + pub confirm_port: bool, /// DTR pin to use for the internal UART hardware. Uses BCM numbering. #[cfg(feature = "raspberry")] #[cfg_attr(feature = "raspberry", clap(long))] diff --git a/espflash/src/cli/serial.rs b/espflash/src/cli/serial.rs index 6aed80bb..badbd045 100644 --- a/espflash/src/cli/serial.rs +++ b/espflash/src/cli/serial.rs @@ -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.confirm_port)?; match &port.port_type { SerialPortType::UsbPort(usb_info) if !matches => { @@ -202,6 +202,7 @@ const KNOWN_DEVICES: &[UsbDevice] = &[ fn select_serial_port( mut ports: Vec, config: &Config, + force_confirm_port: bool, ) -> Result<(SerialPortInfo, bool), Error> { // Does this port match a known one? let matches = |port: &SerialPortInfo| match &port.port_type { @@ -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_confirm_port { + 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");