From f62a1e5b7ca7e22444ba5a9cbc55649407cff9f3 Mon Sep 17 00:00:00 2001 From: Joe Neeman Date: Sat, 5 Aug 2023 17:25:49 -0500 Subject: [PATCH 1/3] Add interactive flag --- espflash/src/cli/mod.rs | 3 +++ espflash/src/cli/serial.rs | 11 ++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/espflash/src/cli/mod.rs b/espflash/src/cli/mod.rs index c3912c16..6324ba86 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 = '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))] diff --git a/espflash/src/cli/serial.rs b/espflash/src/cli/serial.rs index 6aed80bb..15500bf5 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.interactive)?; 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_interactive: 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_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"); From a4b3304c9016ef42aba80e6f5e38d50ec7b3ad28 Mon Sep 17 00:00:00 2001 From: Joe Neeman Date: Mon, 6 Nov 2023 10:03:40 -0600 Subject: [PATCH 2/3] Make it confirm-port --- espflash/src/cli/mod.rs | 4 ++-- espflash/src/cli/serial.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/espflash/src/cli/mod.rs b/espflash/src/cli/mod.rs index 6324ba86..bca8ddf0 100644 --- a/espflash/src/cli/mod.rs +++ b/espflash/src/cli/mod.rs @@ -53,8 +53,8 @@ pub struct ConnectArgs { #[arg(short = 'p', long, env = "ESPFLASH_PORT")] pub port: Option, /// Require confirmation before auto-connecting to a recognized device. - #[arg(short = 'i', long)] - pub interactive: bool, + #[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 15500bf5..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, matches.interactive)?; + let (port, matches) = select_serial_port(ports, config, matches.confirm_port)?; match &port.port_type { SerialPortType::UsbPort(usb_info) if !matches => { @@ -202,7 +202,7 @@ const KNOWN_DEVICES: &[UsbDevice] = &[ fn select_serial_port( mut ports: Vec, config: &Config, - force_interactive: bool, + force_confirm_port: bool, ) -> Result<(SerialPortInfo, bool), Error> { // Does this port match a known one? let matches = |port: &SerialPortInfo| match &port.port_type { @@ -221,7 +221,7 @@ fn select_serial_port( .as_slice() { // There is a unique recognized device. - if !force_interactive { + if !force_confirm_port { return Ok(((*port).to_owned(), true)); } } From de453aed2fb6321fb37bd211fdec0e01d15dc7c5 Mon Sep 17 00:00:00 2001 From: Joe Neeman Date: Mon, 6 Nov 2023 10:50:13 -0600 Subject: [PATCH 3/3] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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