Skip to content

Commit

Permalink
Add value_parser so partition-table-offset accepts offset expressed…
Browse files Browse the repository at this point in the history
… in hexadecimal. (#682)

* Add value_parser so `partition-table-offset` accepts offset expressed in hexadecimal.

* Add changelog entry.
  • Loading branch information
jnross committed Sep 17, 2024
1 parent 46b5b8d commit 62cec88
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 20 additions & 1 deletion espflash/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ pub struct ImageArgs {
#[arg(long, short = 'T', value_name = "FILE")]
pub partition_table: Option<PathBuf>,
/// Partition table offset
#[arg(long, value_name = "OFFSET")]
#[arg(long, value_name = "OFFSET", value_parser = parse_uint32)]
pub partition_table_offset: Option<u32>,
/// Label of target app partition
#[arg(long, value_name = "LABEL")]
Expand Down Expand Up @@ -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));
}
}

0 comments on commit 62cec88

Please sign in to comment.