From 45e0127dc3748ab505f93597d269c49354d21103 Mon Sep 17 00:00:00 2001 From: Joseph Ross Date: Wed, 20 Sep 2023 08:12:54 -0700 Subject: [PATCH] Avoid changes to `cli/mod.rs` --- espflash/src/bin/espflash.rs | 52 +++++++++++++++++++++++++++++++++--- espflash/src/cli/mod.rs | 45 ------------------------------- 2 files changed, 48 insertions(+), 49 deletions(-) diff --git a/espflash/src/bin/espflash.rs b/espflash/src/bin/espflash.rs index 8cb984f3..273f36a0 100644 --- a/espflash/src/bin/espflash.rs +++ b/espflash/src/bin/espflash.rs @@ -1,17 +1,17 @@ use std::{ fs::{self, File}, io::Read, + num::ParseIntError, path::PathBuf, }; use clap::{Args, CommandFactory, Parser, Subcommand}; -use espflash::cli::EraseRegionArgs; use espflash::{ cli::{ self, board_info, completions, config::Config, connect, erase_partitions, flash_elf_image, - monitor::monitor, parse_partition_table, parse_uint32, partition_table, print_board_info, - save_elf_as_image, serial_monitor, CompletionsArgs, ConnectArgs, EraseFlashArgs, - ErasePartsArgs, EspflashProgress, FlashConfigArgs, MonitorArgs, PartitionTableArgs, + monitor::monitor, parse_partition_table, partition_table, print_board_info, + save_elf_as_image, serial_monitor, CompletionsArgs, ConnectArgs, EspflashProgress, + FlashConfigArgs, MonitorArgs, PartitionTableArgs, }, image_format::ImageFormatKind, logging::initialize_logger, @@ -84,6 +84,45 @@ enum Commands { WriteBin(WriteBinArgs), } +/// Erase entire flash of target device +#[derive(Debug, Args)] +pub struct EraseFlashArgs { + /// Connection configuration + #[clap(flatten)] + pub connect_args: ConnectArgs, +} + +/// Erase named partitions based on provided partition table +#[derive(Debug, Args)] +pub struct ErasePartsArgs { + /// Connection configuration + #[clap(flatten)] + pub connect_args: ConnectArgs, + + #[arg(value_name = "LABELS", value_delimiter = ',')] + pub erase_parts: Vec, + + /// Input partition table + #[arg(long, value_name = "FILE")] + pub partition_table: PathBuf, +} + +/// Erase specified region of flash +#[derive(Debug, Args)] +pub struct EraseRegionArgs { + /// Connection configuration + #[clap(flatten)] + pub connect_args: ConnectArgs, + + /// Offset to start erasing from + #[arg(value_name = "OFFSET", value_parser = parse_uint32)] + pub addr: u32, + + /// Size of the region to erase + #[arg(value_name = "SIZE", value_parser = parse_uint32)] + pub size: u32, +} + #[derive(Debug, Args)] struct FlashArgs { /// Connection configuration @@ -127,6 +166,11 @@ struct WriteBinArgs { connect_args: ConnectArgs, } +/// Parses a string as a 32-bit unsigned integer. +fn parse_uint32(input: &str) -> Result { + parse_int::parse(input) +} + fn main() -> Result<()> { miette::set_panic_hook(); initialize_logger(LevelFilter::Info); diff --git a/espflash/src/cli/mod.rs b/espflash/src/cli/mod.rs index e755da2d..0354d617 100644 --- a/espflash/src/cli/mod.rs +++ b/espflash/src/cli/mod.rs @@ -7,7 +7,6 @@ //! [cargo-espflash]: https://crates.io/crates/cargo-espflash //! [espflash]: https://crates.io/crates/espflash -use std::num::ParseIntError; use std::{ collections::HashMap, fs, @@ -163,50 +162,6 @@ pub struct MonitorArgs { connect_args: ConnectArgs, } -/// Erase entire flash of target device -#[derive(Debug, Args)] -pub struct EraseFlashArgs { - /// Connection configuration - #[clap(flatten)] - pub connect_args: ConnectArgs, -} - -/// Erase named partitions based on provided partition table -#[derive(Debug, Args)] -pub struct ErasePartsArgs { - /// Connection configuration - #[clap(flatten)] - pub connect_args: ConnectArgs, - - #[arg(value_name = "LABELS", value_delimiter = ',')] - pub erase_parts: Vec, - - /// Input partition table - #[arg(long, value_name = "FILE")] - pub partition_table: PathBuf, -} - -/// Erase specified region of flash -#[derive(Debug, Args)] -pub struct EraseRegionArgs { - /// Connection configuration - #[clap(flatten)] - pub connect_args: ConnectArgs, - - /// Offset to start erasing from - #[arg(value_name = "OFFSET", value_parser = parse_uint32)] - pub addr: u32, - - /// Size of the region to erase - #[arg(value_name = "SIZE", value_parser = parse_uint32)] - pub size: u32, -} - -/// Parses a string as a 32-bit unsigned integer. -pub fn parse_uint32(input: &str) -> Result { - parse_int::parse(input) -} - /// Select a serial port and establish a connection with a target device pub fn connect(args: &ConnectArgs, config: &Config) -> Result { let port_info = get_serial_port_info(args, config)?;