Skip to content

Commit

Permalink
add some error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdallas committed Nov 3, 2022
1 parent fbcb424 commit 49e97f7
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,25 @@ async fn main() -> Result<(), GertError> {
let use_human_readable = matches.is_present("human_readable");
// restrict downloads to these subreddits
let subreddits: Vec<&str> = matches.values_of("subreddits").unwrap().collect();
let limit = matches.value_of("limit").unwrap().parse::<u32>().expect("Limit must be a number");
let limit = match matches.value_of("limit").unwrap().parse::<u32>() {
Ok(limit) => limit,
Err(_) => {
let err = clap::Error::with_description("Limit must be a number", clap::ErrorKind::InvalidValue);
err.exit();
}
};
let period = matches.value_of("period");
let feed = matches.value_of("feed").unwrap();
let pattern = match matches.value_of("match") {
Some(pattern) => regex::Regex::new(pattern).expect("Invalid regex pattern"),
Some(pattern) => {
match regex::Regex::new(pattern) {
Ok(reg) => reg,
Err(_) => {
let err = clap::Error::with_description("Invalid regex pattern", clap::ErrorKind::InvalidValue);
err.exit();
}
}
},
None => regex::Regex::new(".*").unwrap(),
};

Expand Down

0 comments on commit 49e97f7

Please sign in to comment.