Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add interactive flag #455

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
SergioGasquez marked this conversation as resolved.
Show resolved Hide resolved
SergioGasquez marked this conversation as resolved.
Show resolved Hide resolved
/// 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 {
SergioGasquez marked this conversation as resolved.
Show resolved Hide resolved
// Multiple serial ports detected.
info!("Detected {} serial ports", ports.len());
info!("Ports which match a known common dev board are highlighted");
Expand Down