Add support for parsing integers from all possible formats in the crate. Also improve some docs.
diff --git a/cli/Cargo.toml b/cli/Cargo.toml index c58f4cf..2dfcabf 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml
@@ -34,4 +34,4 @@ parse_int = "0.5.0" num-traits = "0.2.14" bitfield = "0.13.2" -jep106 = "0.2.4" +jep106 = "0.2.4" \ No newline at end of file
diff --git a/cli/src/main.rs b/cli/src/main.rs index 1b5ab31..dd86665 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs
@@ -23,32 +23,6 @@ use std::path::PathBuf; use std::time::Instant; -fn parse_hex(src: &str) -> Result<u32, ParseIntError> { - u32::from_str_radix(src, 16) -} - -arg_enum! { - #[derive(Debug, Clone, Copy)] - enum DownloadFileType { - Elf, - Hex, - Bin, - } -} - -impl DownloadFileType { - fn into(self, base_address: Option<u32>, skip: Option<u32>) -> Format { - match self { - DownloadFileType::Elf => Format::Elf, - DownloadFileType::Hex => Format::Hex, - DownloadFileType::Bin => Format::Bin(BinOptions { - base_address, - skip: skip.unwrap_or(0), - }), - } - } -} - #[derive(StructOpt)] #[structopt( name = "Probe-rs CLI", @@ -98,10 +72,11 @@ #[structopt(flatten)] common: ProbeOptions, - /// The address of the memory to dump from the target (in hexadecimal without 0x prefix) - #[structopt(parse(try_from_str = parse_hex))] + /// The address of the memory to dump from the target. + #[structopt(parse(try_from_str = parse_u32))] loc: u32, - /// The amount of memory (in words) to dump + /// The amount of memory (in words) to dump. + #[structopt(parse(try_from_str = parse_u32))] words: u32, }, /// Download memory to attached target @@ -120,10 +95,10 @@ format: DownloadFileType, /// The address in memory where the binary will be put at. This is only considered when `bin` is selected as the format. - #[structopt(long)] + #[structopt(long, parse(try_from_str = parse_u32))] base_address: Option<u32>, /// The number of bytes to skip at the start of the binary file. This is only considered when `bin` is selected as the format. - #[structopt(long)] + #[structopt(long, parse(try_from_str = parse_u32))] skip_bytes: Option<u32>, /// The path to the file to be downloaded to the flash @@ -143,8 +118,8 @@ #[structopt(flatten)] common: ProbeOptions, - /// The address of the memory to dump from the target (in hexadecimal without 0x prefix) - #[structopt(parse(try_from_str = parse_hex))] + /// The address of the memory to dump from the target. + #[structopt(parse(try_from_str = parse_u32))] loc: u32, }, } @@ -381,3 +356,29 @@ Ok(()) } + +arg_enum! { + #[derive(Debug, Clone, Copy)] + enum DownloadFileType { + Elf, + Hex, + Bin, + } +} + +impl DownloadFileType { + fn into(self, base_address: Option<u32>, skip: Option<u32>) -> Format { + match self { + DownloadFileType::Elf => Format::Elf, + DownloadFileType::Hex => Format::Hex, + DownloadFileType::Bin => Format::Bin(BinOptions { + base_address, + skip: skip.unwrap_or(0), + }), + } + } +} + +fn parse_u32(input: &str) -> Result<u32, ParseIntError> { + parse_int::parse(input) +}