From 62cec888d732ba6a6148e7e8eff1884a6bc701c2 Mon Sep 17 00:00:00 2001 From: Joseph Ross Date: Tue, 17 Sep 2024 01:30:50 -0700 Subject: [PATCH] Add value_parser so `partition-table-offset` accepts offset expressed in hexadecimal. (#682) * Add value_parser so `partition-table-offset` accepts offset expressed in hexadecimal. * Add changelog entry. --- CHANGELOG.md | 1 + espflash/src/cli/mod.rs | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fba3c69..05845afe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added ### Fixed +- Fixed `partition-table-offset` argument to accept offsets in hexadecimal (#682) ### Changed diff --git a/espflash/src/cli/mod.rs b/espflash/src/cli/mod.rs index 8f349e64..62ee4f5b 100644 --- a/espflash/src/cli/mod.rs +++ b/espflash/src/cli/mod.rs @@ -236,7 +236,7 @@ pub struct ImageArgs { #[arg(long, short = 'T', value_name = "FILE")] pub partition_table: Option, /// Partition table offset - #[arg(long, value_name = "OFFSET")] + #[arg(long, value_name = "OFFSET", value_parser = parse_uint32)] pub partition_table_offset: Option, /// Label of target app partition #[arg(long, value_name = "LABEL")] @@ -843,3 +843,22 @@ pub fn make_flash_data( image_args.min_chip_rev, ) } + +mod test { + use crate::cli::FlashArgs; + use clap::Parser; + + #[derive(Parser)] + struct TestParser { + #[clap(flatten)] + args: FlashArgs, + } + + #[test] + fn test_parse_hex_partition_table_offset() { + let command = "command --partition-table-offset 0x8000"; + let iter = command.split_whitespace(); + let parser = TestParser::parse_from(iter); + assert_eq!(parser.args.image.partition_table_offset, Some(0x8000)); + } +}