Skip to content

Commit db6d98a

Browse files
committed
Format cargo-espflash and espflash packages
1 parent 2a3e39f commit db6d98a

File tree

18 files changed

+117
-96
lines changed

18 files changed

+117
-96
lines changed

cargo-espflash/src/main.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,7 @@ use std::{
77
use cargo_metadata::{Message, MetadataCommand};
88
use clap::{Args, CommandFactory, Parser, Subcommand};
99
use espflash::{
10-
cli::{
11-
self, board_info, checksum_md5, completions, config::Config, connect, erase_flash,
12-
erase_partitions, erase_region, flash_elf_image, make_flash_data, monitor::monitor,
13-
partition_table, print_board_info, read_flash, save_elf_as_image, serial_monitor,
14-
ChecksumMd5Args, CompletionsArgs, ConnectArgs, EraseFlashArgs, EraseRegionArgs,
15-
EspflashProgress, FlashConfigArgs, MonitorArgs, PartitionTableArgs, ReadFlashArgs,
16-
},
10+
cli::{self, config::Config, monitor::monitor, *},
1711
error::Error as EspflashError,
1812
flasher::parse_partition_table,
1913
logging::initialize_logger,
@@ -305,8 +299,8 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
305299
)?;
306300
flasher.verify_minimum_revision(args.flash_args.image.min_chip_rev)?;
307301

308-
// If the user has provided a flash size via a command-line argument or config, we'll
309-
// override the detected (or default) value with this.
302+
// If the user has provided a flash size via a command-line argument or config,
303+
// we'll override the detected (or default) value with this.
310304
if let Some(flash_size) = args.build_args.flash_config_args.flash_size {
311305
flasher.set_flash_size(flash_size);
312306
} else if let Some(flash_size) = config.flash.size {
@@ -493,8 +487,8 @@ fn build(
493487
match message.into_diagnostic()? {
494488
Message::BuildScriptExecuted(script) => {
495489
// We can't use the `Index` implementation on `Metadata` because `-Zbuild-std`
496-
// pulls in dependencies not listed in the metadata which then causes the `Index`
497-
// implementation to panic.
490+
// pulls in dependencies not listed in the metadata which then causes the
491+
// `Index` implementation to panic.
498492
let Some(package) = metadata.packages.iter().find(|p| p.id == script.package_id)
499493
else {
500494
continue;

espflash/src/bin/espflash.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@ use std::{
66

77
use clap::{Args, CommandFactory, Parser, Subcommand};
88
use espflash::{
9-
cli::{
10-
self, board_info, checksum_md5, completions, config::Config, connect, erase_flash,
11-
erase_partitions, erase_region, flash_elf_image, make_flash_data, monitor::monitor,
12-
parse_uint32, partition_table, print_board_info, read_flash, save_elf_as_image,
13-
serial_monitor, ChecksumMd5Args, CompletionsArgs, ConnectArgs, EraseFlashArgs,
14-
EraseRegionArgs, EspflashProgress, FlashConfigArgs, MonitorArgs, PartitionTableArgs,
15-
ReadFlashArgs,
16-
},
9+
cli::{self, config::Config, monitor::monitor, *},
1710
error::Error,
1811
flasher::parse_partition_table,
1912
logging::initialize_logger,

espflash/src/cli/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ use miette::{IntoDiagnostic, Result, WrapErr};
1919
use serde::{Deserialize, Serialize};
2020
use serialport::UsbPortInfo;
2121

22-
use crate::error::Error;
23-
use crate::flasher::FlashSettings;
22+
use crate::{error::Error, flasher::FlashSettings};
2423

2524
/// A configured, known serial connection
2625
#[derive(Debug, Deserialize, Serialize, Default, Clone)]
@@ -167,9 +166,10 @@ impl Config {
167166

168167
#[cfg(test)]
169168
mod tests {
170-
use super::*;
171169
use serde::Deserialize;
172170

171+
use super::*;
172+
173173
#[derive(Debug, Deserialize, Serialize)]
174174
struct TestData {
175175
#[serde(serialize_with = "parse_u16_hex", deserialize_with = "parse_hex_u16")]

espflash/src/cli/mod.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,14 @@ use crate::{
3737
elf::ElfFirmwareImage,
3838
error::{Error, MissingPartition, MissingPartitionTable},
3939
flasher::{
40-
parse_partition_table, FlashData, FlashFrequency, FlashMode, FlashSettings, FlashSize,
41-
Flasher, ProgressCallbacks,
40+
parse_partition_table,
41+
FlashData,
42+
FlashFrequency,
43+
FlashMode,
44+
FlashSettings,
45+
FlashSize,
46+
Flasher,
47+
ProgressCallbacks,
4248
},
4349
targets::{Chip, XtalFrequency},
4450
};
@@ -857,9 +863,10 @@ pub fn make_flash_data(
857863
}
858864

859865
mod test {
860-
use crate::cli::FlashArgs;
861866
use clap::Parser;
862867

868+
use crate::cli::FlashArgs;
869+
863870
#[derive(Parser)]
864871
struct TestParser {
865872
#[clap(flatten)]

espflash/src/cli/monitor/external_processors.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
#![allow(clippy::needless_doctest_main)]
22
//! External processor support
33
//!
4-
//! Via the command line argument `--processors` you can instruct espflash to run external executables to pre-process
5-
//! the logs received from the target. Multiple processors are supported by separating them via `,`. Processors are executed in the specified order.
4+
//! Via the command line argument `--processors` you can instruct espflash to
5+
//! run external executables to pre-process the logs received from the target.
6+
//! Multiple processors are supported by separating them via `,`. Processors are
7+
//! executed in the specified order.
68
//!
7-
//! You can use full-qualified paths or run an executable which is already in the search path.
9+
//! You can use full-qualified paths or run an executable which is already in
10+
//! the search path.
811
//!
9-
//! A processors reads from stdin and output to stdout. Be aware this runs before further processing by espflash.
10-
//! i.e. addresses are not resolved and when using `defmt` you will see encoded data.
12+
//! A processors reads from stdin and output to stdout. Be aware this runs
13+
//! before further processing by espflash. i.e. addresses are not resolved and
14+
//! when using `defmt` you will see encoded data.
1115
//!
12-
//! Additionally be aware that you might receive chunked data which is not always split at valid UTF character boundaries.
16+
//! Additionally be aware that you might receive chunked data which is not
17+
//! always split at valid UTF character boundaries.
1318
//!
14-
//! The executable will get the path of the ELF file as the first argument if available.
19+
//! The executable will get the path of the ELF file as the first argument if
20+
//! available.
1521
//!
1622
//! Example processor which turns some letters into uppercase
1723
//! ```rust,no_run

espflash/src/cli/monitor/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ use std::{
1616
time::Duration,
1717
};
1818

19-
use crossterm::event::KeyEventKind;
2019
use crossterm::{
21-
event::{poll, read, Event, KeyCode, KeyEvent, KeyModifiers},
20+
event::{poll, read, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers},
2221
terminal::{disable_raw_mode, enable_raw_mode},
2322
};
2423
use external_processors::ExternalProcessors;
@@ -68,7 +67,8 @@ impl Drop for RawModeGuard {
6867
}
6968
}
7069

71-
/// Open a serial monitor on the given serial port, using the given input parser.
70+
/// Open a serial monitor on the given serial port, using the given input
71+
/// parser.
7272
#[allow(clippy::too_many_arguments)]
7373
pub fn monitor(
7474
mut serial: Port,

espflash/src/cli/monitor/parser/esp_defmt.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ impl FrameDelimiter {
8181
}
8282

8383
if !self.in_frame {
84-
// If we have a 0xFF byte at the end, we should assume it's the start of a new frame.
84+
// If we have a 0xFF byte at the end, we should assume it's the start of a new
85+
// frame.
8586
let consume = if self.buffer.ends_with(&[0xFF]) {
8687
&self.buffer[..self.buffer.len() - 1]
8788
} else {
@@ -102,7 +103,8 @@ pub struct EspDefmt {
102103
}
103104

104105
impl EspDefmt {
105-
/// Loads symbols from the ELF file (if provided) and initializes the context.
106+
/// Loads symbols from the ELF file (if provided) and initializes the
107+
/// context.
106108
fn load_table(elf: Option<&[u8]>) -> Result<Table> {
107109
let Some(elf) = elf else {
108110
bail!(DefmtError::NoElf);

espflash/src/cli/monitor/parser/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ impl Utf8Merger {
7373
let mut buffer = std::mem::take(&mut self.incomplete_utf8_buffer);
7474
buffer.extend(normalized(buff.iter().copied()));
7575

76-
// look for longest slice that we can then lossily convert without introducing errors for
77-
// partial sequences (#457)
76+
// look for longest slice that we can then lossily convert without introducing
77+
// errors for partial sequences (#457)
7878
let mut len = 0;
7979

8080
loop {

espflash/src/cli/monitor/symbols.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use std::error::Error;
33
use addr2line::{
44
gimli::{EndianRcSlice, RunTimeEndian},
55
object::{read::File, Object, ObjectSegment, ObjectSymbol},
6-
Context, LookupResult,
6+
Context,
7+
LookupResult,
78
};
89

910
// Wrapper around addr2line that allows to look up function names and
@@ -21,7 +22,8 @@ impl<'sym> Symbols<'sym> {
2122
Ok(Self { file, ctx })
2223
}
2324

24-
/// Returns the name of the function at the given address, if one can be found.
25+
/// Returns the name of the function at the given address, if one can be
26+
/// found.
2527
pub fn get_name(&self, addr: u64) -> Option<String> {
2628
// no need to try an address not contained in any segment
2729
if !self.file.segments().any(|segment| {
@@ -51,7 +53,8 @@ impl<'sym> Symbols<'sym> {
5153
.and_then(|name| name.demangle().map(|s| s.into_owned()).ok())
5254
})
5355
.or_else(|| {
54-
// Don't use `symbol_map().get(addr)` - it's documentation says "Get the symbol before the given address." which might be totally wrong
56+
// Don't use `symbol_map().get(addr)` - it's documentation says "Get the symbol
57+
// before the given address." which might be totally wrong
5558
let symbol = self.file.symbols().find(|symbol| {
5659
(symbol.address()..=(symbol.address() + symbol.size())).contains(&addr)
5760
});
@@ -70,7 +73,8 @@ impl<'sym> Symbols<'sym> {
7073
})
7174
}
7275

73-
/// Returns the file name and line number of the function at the given address, if one can be.
76+
/// Returns the file name and line number of the function at the given
77+
/// address, if one can be.
7478
pub fn get_location(&self, addr: u64) -> Option<(String, u32)> {
7579
// Find the location which `addr` is in. If we can dedetermine a file name and
7680
// line number for this function we will return them both in a tuple.

espflash/src/cli/serial.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ fn find_serial_port(ports: &[SerialPortInfo], name: &str) -> Result<SerialPortIn
105105
}
106106
}
107107

108-
/// Serialport's auto-detect doesn't provide any port information when using MUSL
109-
/// Linux we can do some manual parsing of sysfs to get the relevant bits
108+
/// Serialport's auto-detect doesn't provide any port information when using
109+
/// MUSL Linux we can do some manual parsing of sysfs to get the relevant bits
110110
/// without udev
111111
#[cfg(all(target_os = "linux", target_env = "musl"))]
112112
fn detect_usb_serial_ports(_list_all_ports: bool) -> Result<Vec<SerialPortInfo>> {
@@ -129,7 +129,8 @@ fn detect_usb_serial_ports(_list_all_ports: bool) -> Result<Vec<SerialPortInfo>>
129129
};
130130

131131
// This will give something like:
132-
// `/sys/devices/pci0000:00/0000:00:07.1/0000:0c:00.3/usb5/5-3/5-3.1/5-3.1:1.0/ttyUSB0/tty/ttyUSB0`
132+
// `/sys/devices/pci0000:00/0000:00:07.1/0000:0c:00.3/usb5/5-3/5-3.1/5-3.1:1.0/
133+
// ttyUSB0/tty/ttyUSB0`
133134
let mut parent_dev = path.canonicalize().ok()?;
134135

135136
// Walk up 3 dirs to get to the device hosting the tty:

0 commit comments

Comments
 (0)