Skip to content

Commit 194cc45

Browse files
committed
Address issues raised in review
- serial port name comparison is now case-insensitive - added docstrings which were missing for some subcommands - espflash now displays help and exits if no arguments provided
1 parent 696375c commit 194cc45

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

cargo-espflash/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ struct EspFlashOpts {
5353

5454
#[derive(Parser)]
5555
pub enum SubCommand {
56+
/// Display information about the connected board and exit without flashing
5657
BoardInfo(ConnectOpts),
58+
/// Save the image to disk instead of flashing to device
5759
SaveImage(SaveImageOpts),
5860
}
5961

@@ -82,7 +84,6 @@ pub struct BuildOpts {
8284
pub unstable: Option<Vec<String>>,
8385
}
8486

85-
/// Save the image to disk instead of flashing to device
8687
#[derive(Parser)]
8788
pub struct SaveImageOpts {
8889
#[clap(flatten)]

espflash/src/cli/serial.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub fn get_serial_port_info(
6464
fn find_serial_port(ports: &[SerialPortInfo], name: String) -> Option<SerialPortInfo> {
6565
ports
6666
.iter()
67-
.find(|port| port.port_name == name)
67+
.find(|port| port.port_name.to_lowercase() == name.to_lowercase())
6868
.map(|port| port.to_owned())
6969
}
7070

espflash/src/main.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ struct Opts {
2828

2929
#[derive(Parser)]
3030
pub enum SubCommand {
31+
/// Display information about the connected board and exit without flashing
3132
BoardInfo(ConnectOpts),
33+
/// Save the image to disk instead of flashing to device
3234
SaveImage(SaveImageOpts),
3335
}
3436

35-
/// Save the image to disk instead of flashing to device
3637
#[derive(Parser)]
3738
pub struct SaveImageOpts {
3839
/// Image format to flash
@@ -52,8 +53,15 @@ fn main() -> Result<()> {
5253
let mut opts = Opts::parse();
5354
let config = Config::load()?;
5455

55-
// If only a single argument is passed, it's always going to be the ELF file. In
56-
// the case that the serial port was not provided as a command-line argument,
56+
// If neither the IMAGE nor SERIAL arguments have been provided, print the help
57+
// message and exit.
58+
if opts.image.is_none() && opts.connect_opts.serial.is_none() {
59+
Opts::into_app().print_help().ok();
60+
return Ok(());
61+
}
62+
63+
// If only a single argument is passed, it *should* always be the ELF file.
64+
// In the case that the serial port was not provided as a command-line argument,
5765
// we will either load the value specified in the configuration file or do port
5866
// auto-detection instead.
5967
if opts.image.is_none() && opts.connect_opts.serial.is_some() {

0 commit comments

Comments
 (0)