Skip to content

Commit 1369d86

Browse files
committed
fix: Use a single config struct in cargo-espflash
1 parent 6b03161 commit 1369d86

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

cargo-espflash/src/main.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use espflash::{
1010
Error as EspflashError,
1111
cli::{
1212
self,
13-
config::{Config, PortConfig},
13+
config::Config,
1414
monitor::{check_monitor_args, monitor},
1515
*,
1616
},
@@ -231,27 +231,24 @@ fn main() -> Result<()> {
231231
// Load any user configuration, if present.
232232
let config = Config::load()?;
233233

234-
// Load any user ports configuration, if present.
235-
let ports_config = PortConfig::load()?;
236-
237234
// Execute the correct action based on the provided subcommand and its
238235
// associated arguments.
239236
match args {
240-
Commands::BoardInfo(args) => board_info(&args, &config, &ports_config),
241-
Commands::ChecksumMd5(args) => checksum_md5(&args, &config, &ports_config),
237+
Commands::BoardInfo(args) => board_info(&args, &config),
238+
Commands::ChecksumMd5(args) => checksum_md5(&args, &config),
242239
Commands::Completions(args) => completions(&args, &mut Cli::command(), "cargo"),
243-
Commands::EraseFlash(args) => erase_flash(args, &config, &ports_config),
244-
Commands::EraseParts(args) => erase_parts(args, &config, &ports_config),
245-
Commands::EraseRegion(args) => erase_region(args, &config, &ports_config),
246-
Commands::Flash(args) => flash(args, &config, &ports_config),
247-
Commands::HoldInReset(args) => hold_in_reset(args, &config, &ports_config),
248-
Commands::ListPorts(args) => list_ports(&args, &ports_config),
249-
Commands::Monitor(args) => serial_monitor(args, &config, &ports_config),
240+
Commands::EraseFlash(args) => erase_flash(args, &config),
241+
Commands::EraseParts(args) => erase_parts(args, &config),
242+
Commands::EraseRegion(args) => erase_region(args, &config),
243+
Commands::Flash(args) => flash(args, &config),
244+
Commands::HoldInReset(args) => hold_in_reset(args, &config),
245+
Commands::ListPorts(args) => list_ports(&args, &config.port_config),
246+
Commands::Monitor(args) => serial_monitor(args, &config),
250247
Commands::PartitionTable(args) => partition_table(args),
251-
Commands::ReadFlash(args) => read_flash(args, &config, &ports_config),
252-
Commands::Reset(args) => reset(args, &config, &ports_config),
248+
Commands::ReadFlash(args) => read_flash(args, &config),
249+
Commands::Reset(args) => reset(args, &config),
253250
Commands::SaveImage(args) => save_image(args, &config),
254-
Commands::WriteBin(args) => write_bin(args, &config, &ports_config),
251+
Commands::WriteBin(args) => write_bin(args, &config),
255252
}
256253
}
257254

@@ -270,7 +267,7 @@ pub fn erase_parts(args: ErasePartsArgs, config: &Config) -> Result<()> {
270267
let partition_table = args
271268
.partition_table
272269
.as_deref()
273-
.or(config.partition_table.as_deref());
270+
.or(config.project_config.partition_table.as_deref());
274271

275272
let mut flasher = connect(&args.connect_args, config, false, false)?;
276273
let chip = flasher.chip();
@@ -296,7 +293,6 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
296293
let mut flasher = connect(
297294
&args.connect_args,
298295
config,
299-
ports_config,
300296
args.flash_args.no_verify,
301297
args.flash_args.no_skip,
302298
)?;
@@ -306,7 +302,7 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
306302
// we'll override the detected (or default) value with this.
307303
if let Some(flash_size) = args.build_args.flash_config_args.flash_size {
308304
flasher.set_flash_size(flash_size);
309-
} else if let Some(flash_size) = config.flash.size {
305+
} else if let Some(flash_size) = config.project_config.flash.size {
310306
flasher.set_flash_size(flash_size);
311307
}
312308

@@ -333,7 +329,7 @@ fn flash(args: FlashArgs, config: &Config) -> Result<()> {
333329
let mut flash_config = args.build_args.flash_config_args;
334330
flash_config.flash_size = flash_config
335331
.flash_size // Use CLI argument if provided
336-
.or(config.flash.size) // If no CLI argument, try the config file
332+
.or(config.project_config.flash.size) // If no CLI argument, try the config file
337333
.or_else(|| flasher.flash_detect().ok().flatten()) // Try detecting flash size next
338334
.or_else(|| Some(FlashSize::default())); // Otherwise, use a reasonable default value
339335

@@ -580,7 +576,7 @@ fn save_image(args: SaveImageArgs, config: &Config) -> Result<()> {
580576
let mut flash_config = args.build_args.flash_config_args;
581577
flash_config.flash_size = flash_config
582578
.flash_size // Use CLI argument if provided
583-
.or(config.flash.size) // If no CLI argument, try the config file
579+
.or(config.project_config.flash.size) // If no CLI argument, try the config file
584580
.or_else(|| Some(FlashSize::default())); // Otherwise, use a reasonable default value
585581

586582
let flash_data = make_flash_data(

0 commit comments

Comments
 (0)