Skip to content

Commit

Permalink
Add interactive flag (#455)
Browse files Browse the repository at this point in the history
* Add interactive flag

* Make it confirm-port

* Add changelog entry
  • Loading branch information
jneem authored Nov 7, 2023
1 parent 39fbdac commit 3051241
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
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 = '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))]
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.confirm_port)?;

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_confirm_port: 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_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");
Expand Down

0 comments on commit 3051241

Please sign in to comment.