Skip to content

Commit

Permalink
Simplifies argument parsing Ref. #2.
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Leggett committed Oct 2, 2018
1 parent eccebce commit 38da5f2
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,15 @@ impl Config {
command = Some(String::from("info"));
fund_name = list_matches.value_of("name");
},
("", None) => command = Some(String::from("list")),
("", None) => command = Some(String::from("info")),
_ => unreachable!(),
}

let fund_name = fund_name.map_or(None, |x| Some(String::from(x)));

let amount = match amount {
Some(x) => {
Some(x.replace(".", "").parse::<i32>()?)
},
None => None,
};
let amount = amount.map_or(Ok(None), |x| x.replace(".", "").parse::<i32>().map(Some))?;

let goal = match goal {
Some(x) => {
Some(x.replace(".", "").parse::<i32>()?)
},
None => None,
};
let goal = goal.map_or(Ok(None), |x| x.replace(".", "").parse::<i32>().map(Some))?;

Ok(Config { configfile, fundfile, command, fund_name, amount, goal })
}
Expand Down

0 comments on commit 38da5f2

Please sign in to comment.