Add support for parsing integers from all possible formats in the  crate. Also improve some docs.
@@ -23,32 +23,6 @@ use std::num::ParseIntError;
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 @@ enum Cli {
#[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 @@ enum Cli {
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 @@ enum Cli {
#[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 @@ fn debug(shared_options: &CoreOptions, common: &ProbeOptions, exe: Option<PathBu
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)
+}
