Skip to content

Commit 3051241

Browse files
authored
Add interactive flag (#455)
* Add interactive flag * Make it confirm-port * Add changelog entry
1 parent 39fbdac commit 3051241

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Read esp-println generated defmt messages (#466)
1313
- Add --target-app-partition argument to flash command (#461)
14+
- Add --confirm-port argument to flash command (#455)
1415

1516
### Fixed
1617

espflash/src/cli/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ pub struct ConnectArgs {
5252
/// Serial port connected to target device
5353
#[arg(short = 'p', long, env = "ESPFLASH_PORT")]
5454
pub port: Option<String>,
55+
/// Require confirmation before auto-connecting to a recognized device.
56+
#[arg(short = 'c', long)]
57+
pub confirm_port: bool,
5558
/// DTR pin to use for the internal UART hardware. Uses BCM numbering.
5659
#[cfg(feature = "raspberry")]
5760
#[cfg_attr(feature = "raspberry", clap(long))]

espflash/src/cli/serial.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn get_serial_port_info(
4040
} else if let Some(serial) = &config.connection.serial {
4141
find_serial_port(&ports, serial)
4242
} else {
43-
let (port, matches) = select_serial_port(ports, config)?;
43+
let (port, matches) = select_serial_port(ports, config, matches.confirm_port)?;
4444

4545
match &port.port_type {
4646
SerialPortType::UsbPort(usb_info) if !matches => {
@@ -202,6 +202,7 @@ const KNOWN_DEVICES: &[UsbDevice] = &[
202202
fn select_serial_port(
203203
mut ports: Vec<SerialPortInfo>,
204204
config: &Config,
205+
force_confirm_port: bool,
205206
) -> Result<(SerialPortInfo, bool), Error> {
206207
// Does this port match a known one?
207208
let matches = |port: &SerialPortInfo| match &port.port_type {
@@ -220,8 +221,12 @@ fn select_serial_port(
220221
.as_slice()
221222
{
222223
// There is a unique recognized device.
223-
Ok(((*port).to_owned(), true))
224-
} else if ports.len() > 1 {
224+
if !force_confirm_port {
225+
return Ok(((*port).to_owned(), true));
226+
}
227+
}
228+
229+
if ports.len() > 1 {
225230
// Multiple serial ports detected.
226231
info!("Detected {} serial ports", ports.len());
227232
info!("Ports which match a known common dev board are highlighted");

0 commit comments

Comments
 (0)