Skip to content

Commit 801331f

Browse files
authored
Merge pull request #61 from porglezomp/release/0.4.1
Release/0.4.1
2 parents 5b1401f + 91d2913 commit 801331f

File tree

9 files changed

+82
-63
lines changed

9 files changed

+82
-63
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "feedburst"
3-
version = "0.4.0"
3+
version = "0.4.1"
44
authors = ["Caleb Jones <code@calebjones.net>"]
55
repository = "https://github.com/porglezomp/feedburst"
66
license = "GPL-3.0+"
@@ -25,7 +25,7 @@ chrono = "0.4"
2525
clap = "2.25"
2626
log = "0.3.8"
2727
pretty_env_logger = "0.1.1"
28-
app_dirs = "1.1.1"
28+
app_dirs = "1.2.1"
2929
regex = "0.2"
3030

3131
[[bin]]

src/config.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use std::env;
2-
use std::path::{Path, PathBuf};
32
use std::fs::{File, OpenOptions};
3+
use std::path::{Path, PathBuf};
44
use std::process::Command;
55

66
use error::{Error, ParseError};
77
use feed::FeedInfo;
8-
use platform;
98
use parser;
9+
use platform;
1010

1111
#[derive(Debug, Clone)]
1212
enum PathWrapper {
@@ -62,9 +62,12 @@ impl Args {
6262
.write(true)
6363
.read(true)
6464
.open(path)
65-
.map_err(|err| Error::Msg(format!("Cannot open file {:?}: {}", path, err)))?),
66-
PathWrapper::ErrorIfMissing(ref path) => Ok(File::open(path)
67-
.map_err(|err| Error::Msg(format!("Cannot open file {:?}: {}", path, err)))?),
65+
.map_err(|err| {
66+
Error::Msg(format!("Cannot open file {}: {}", path.display(), err))
67+
})?),
68+
PathWrapper::ErrorIfMissing(ref path) => Ok(File::open(path).map_err(|err| {
69+
Error::Msg(format!("Cannot open file {}: {}", path.display(), err))
70+
})?),
6871
}
6972
}
7073

@@ -76,7 +79,13 @@ impl Args {
7679
.write(true)
7780
.create(true)
7881
.open(&path)
79-
.map_err(|err| Error::Msg(format!("Error opening feed file {:?}: {}", path, err)))
82+
.map_err(|err| {
83+
Error::Msg(format!(
84+
"Error opening feed file {}: {}",
85+
path.display(),
86+
err
87+
))
88+
})
8089
}
8190

8291
pub fn open_url(&self, feed: &FeedInfo, url: &str) -> Result<(), Error> {
@@ -124,7 +133,10 @@ fn feed_path(root: Option<&PathBuf>, name: &str) -> Result<PathBuf, Error> {
124133
debug!("Using feed specified on the command line: {:?}", root);
125134
let root = Path::new(root);
126135
if !root.is_dir() {
127-
Err(Error::Msg(format!("Error: {:?} is not a directory", root)))
136+
Err(Error::Msg(format!(
137+
"Error: {} is not a directory",
138+
root.display()
139+
)))
128140
} else {
129141
Ok(root.join(format!("{}.feed", name)))
130142
}

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::{fmt, io};
21
use reqwest;
2+
use std::{fmt, io};
33

44
#[derive(Debug)]
55
pub enum Error {

src/feed.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
use std::collections::HashSet;
21
use chrono::{DateTime, Utc, Weekday, MIN_DATE};
32
use regex::Regex;
3+
use std::collections::HashSet;
44
use std::io::{self, Read, Seek, Write};
55
use std::path::PathBuf;
66

7-
use parser::parse_events;
87
use error::{Error, ParseError, Span};
8+
use parser::parse_events;
99

1010
#[derive(Hash, Clone, Debug, PartialEq, Eq)]
1111
pub enum UpdateSpec {

src/main.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ use std::str::FromStr;
1313

1414
use clap::{App, Arg};
1515

16-
mod parser;
17-
mod parse_util;
18-
mod feed;
19-
mod error;
2016
mod config;
17+
mod error;
18+
mod feed;
19+
mod parse_util;
20+
mod parser;
2121
mod platform;
2222

23-
use feed::Feed;
2423
use error::{Error, ParseError, Span};
24+
use feed::Feed;
2525

2626
const APP_NAME: &str = env!("CARGO_PKG_NAME");
2727

@@ -85,7 +85,11 @@ fn run() -> Result<(), Error> {
8585
file.read_to_string(&mut text)?;
8686

8787
let make_error_message = |row: usize, span: Span, msg: &str| -> Error {
88-
let mut message = format!("Line {}: Error parsing {:?}\n\n", row, args.config_path(),);
88+
let mut message = format!(
89+
"Line {}: Error parsing {}\n\n",
90+
row,
91+
args.config_path().display(),
92+
);
8993
let line = text.lines().nth(row - 1).unwrap_or_default();
9094
message.push_str(&format!("{}\n", line));
9195
match span {
@@ -110,8 +114,8 @@ fn run() -> Result<(), Error> {
110114

111115
if feeds.is_empty() {
112116
println!(
113-
"You're not following any comics. Add some to your config file at {:?}",
114-
args.config_path(),
117+
"You're not following any comics. Add some to your config file at {}",
118+
args.config_path().display(),
115119
);
116120
return Ok(());
117121
}
@@ -212,7 +216,7 @@ fn fetch_feed(args: &config::Args, mut feed: Feed) -> Result<Feed, Error> {
212216
.filter(|x| {
213217
let keep = feed_info.filter_title(&x.title);
214218
if !keep {
215-
println!("skipping by title: {}", x.title);
219+
debug!("skipping by title: {}", x.title);
216220
}
217221
keep
218222
})
@@ -231,7 +235,7 @@ fn fetch_feed(args: &config::Args, mut feed: Feed) -> Result<Feed, Error> {
231235
let title = title.as_ref().map(|x| &x[..]).unwrap_or("");
232236
let keep = feed_info.filter_title(&title);
233237
if !keep {
234-
println!("skipping by title: {:?}", x.title);
238+
debug!("skipping by title: {:?}", x.title);
235239
}
236240
keep
237241
})
@@ -256,7 +260,8 @@ fn read_feed(args: &config::Args, feed: &mut Feed) -> Result<(), Error> {
256260
}
257261
let plural_feeds = if items.len() == 1 { "comic" } else { "comics" };
258262
println!("{} ({} {})", feed.info.name, items.len(), plural_feeds);
259-
if feed.info
263+
if feed
264+
.info
260265
.update_policies
261266
.contains(&feed::UpdateSpec::OpenAll)
262267
{

src/parser.rs

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,17 @@ fn parse_policy<'a>(buf: &Buffer<'a>) -> Result<(Buffer<'a>, UpdateSpec), ParseE
129129
} else if buf.starts_with_no_case("every") {
130130
let buf = buf.token_no_case("every")?.space()?;
131131
let (buf, count) = parse_number(&buf)?;
132-
let buf = buf.space()?
132+
let buf = buf
133+
.space()?
133134
.first_token_of_no_case(&["days", "day"])?
134135
.0
135136
.space_or_end()?;
136137
Ok((buf, UpdateSpec::Every(count)))
137138
} else if buf.starts_with_no_case("overlap") {
138139
let buf = buf.token_no_case("overlap")?.space()?;
139140
let (buf, count) = parse_number(&buf)?;
140-
let buf = buf.space()?
141+
let buf = buf
142+
.space()?
141143
.first_token_of_no_case(&["comics", "comic"])?
142144
.0
143145
.space_or_end()?;
@@ -167,19 +169,22 @@ fn parse_policy<'a>(buf: &Buffer<'a>) -> Result<(Buffer<'a>, UpdateSpec), ParseE
167169
),
168170
))
169171
} else if buf.starts_with_no_case("open") {
170-
let buf = buf.token_no_case("open")?
172+
let buf = buf
173+
.token_no_case("open")?
171174
.space()?
172175
.token_no_case("all")?
173176
.space_or_end()?;
174177
Ok((buf, UpdateSpec::OpenAll))
175-
} else if buf.text
178+
} else if buf
179+
.text
176180
.chars()
177181
.next()
178182
.map(|x| x.is_digit(10))
179183
.unwrap_or_default()
180184
{
181185
let (buf, count) = parse_number(&buf)?;
182-
let buf = buf.trim_left()
186+
let buf = buf
187+
.trim_left()
183188
.token_no_case("new")?
184189
.space()?
185190
.first_token_of_no_case(&["comics", "comic"])?
@@ -204,7 +209,8 @@ fn parse_policy<'a>(buf: &Buffer<'a>) -> Result<(Buffer<'a>, UpdateSpec), ParseE
204209

205210
fn parse_number<'a>(buf: &Buffer<'a>) -> ParseResult<'a, usize> {
206211
let buf = buf.trim_left();
207-
let end = buf.text
212+
let end = buf
213+
.text
208214
.find(|c: char| !c.is_digit(10))
209215
.unwrap_or_else(|| buf.text.len());
210216
if end == 0 {
@@ -291,18 +297,16 @@ mod test {
291297
"#;
292298
assert_eq!(
293299
parse_config(buf),
294-
Ok(vec![
295-
FeedInfo {
296-
name: "Questionable Content".into(),
297-
url: "http://questionablecontent.net/QCRSS.xml".into(),
298-
update_policies: HashSet::from_iter(vec![
299-
UpdateSpec::On(Weekday::Sat),
300-
UpdateSpec::Every(10),
301-
]),
302-
root: None,
303-
command: None,
304-
},
305-
])
300+
Ok(vec![FeedInfo {
301+
name: "Questionable Content".into(),
302+
url: "http://questionablecontent.net/QCRSS.xml".into(),
303+
update_policies: HashSet::from_iter(vec![
304+
UpdateSpec::On(Weekday::Sat),
305+
UpdateSpec::Every(10),
306+
]),
307+
root: None,
308+
command: None,
309+
}])
306310
);
307311
}
308312

@@ -532,20 +536,18 @@ read 2017-07-18T23:41:58.130248+00:00
532536
";
533537
assert_eq!(
534538
parse_config(pattern_text),
535-
Ok(vec![
536-
FeedInfo {
537-
name: "El Goonish Shive".into(),
538-
url: "http://www.egscomics.com/rss.php".into(),
539-
update_policies: HashSet::from_iter(vec![
540-
UpdateSpec::Filter(FilterType::IgnoreTitle, "EGS:NP".into()),
541-
UpdateSpec::Filter(FilterType::KeepTitle, "\\d{4}-\\d{2}-\\d{2}".into()),
542-
UpdateSpec::Filter(FilterType::KeepUrl, ".".into()),
543-
UpdateSpec::Filter(FilterType::IgnoreUrl, "egsnp".into()),
544-
]),
545-
root: None,
546-
command: None,
547-
},
548-
])
539+
Ok(vec![FeedInfo {
540+
name: "El Goonish Shive".into(),
541+
url: "http://www.egscomics.com/rss.php".into(),
542+
update_policies: HashSet::from_iter(vec![
543+
UpdateSpec::Filter(FilterType::IgnoreTitle, "EGS:NP".into()),
544+
UpdateSpec::Filter(FilterType::KeepTitle, "\\d{4}-\\d{2}-\\d{2}".into()),
545+
UpdateSpec::Filter(FilterType::KeepUrl, ".".into()),
546+
UpdateSpec::Filter(FilterType::IgnoreUrl, "egsnp".into()),
547+
]),
548+
root: None,
549+
command: None,
550+
}])
549551
);
550552
}
551553
}

src/platform/unix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::path::PathBuf;
21
use std::env;
2+
use std::path::PathBuf;
33

44
use error::Error;
55

src/platform/windows.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::path::{Path, PathBuf};
21
use std::ffi::OsStr;
2+
use std::path::{Path, PathBuf};
33
use std::process::Command;
44
use std::{env, fs};
55

@@ -14,8 +14,8 @@ fn app_data_dir() -> Result<PathBuf, Error> {
1414
}
1515

1616
pub fn data_path(path: &str) -> Result<PathBuf, Error> {
17-
let path = app_data_dir()?.join(path).parent().unwrap().into();
18-
fs::create_dir_all(&path).map_err(|err| {
17+
let path = app_data_dir()?.join(path);
18+
fs::create_dir_all(path.parent().unwrap()).map_err(|err| {
1919
Error::Msg(format!(
2020
"Error creating feeds directory {:?}: {}",
2121
path, err

0 commit comments

Comments
 (0)