better debug command parsing

This commit is contained in:
Alex Janka 2023-05-18 11:01:26 +10:00
parent 74dc5ccfb4
commit 48e794861b

View file

@ -22,19 +22,20 @@ impl FromStr for Commands {
type Err = CommandErr;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let lower = s.trim().to_lowercase();
let trimmed = s.trim().to_lowercase();
let words: Vec<&str> = trimmed.split_whitespace().collect();
match lower.as_str() {
"step" => Ok(Self::Step),
"continue" => Ok(Self::Continue),
_ if let Some(addr) = lower.strip_prefix("watch") => {
match words.as_slice() {
["step"] => Ok(Self::Step),
["continue"] => Ok(Self::Continue),
["watch", addr] => {
if let Ok(addr) = u16::from_str_radix(addr.trim().trim_start_matches("0x"), 16) {
Ok(Self::Watch(addr))
} else {
Err(CommandErr::InvalidArgument)
}
}
_ if let Some(addr) = lower.strip_prefix("break") => {
["break", addr] => {
if let Ok(addr) = u16::from_str_radix(addr.trim().trim_start_matches("0x"), 16) {
Ok(Self::Break(addr))
} else {