diff --git a/src/main.rs b/src/main.rs index ef83311..09ee348 100644 --- a/src/main.rs +++ b/src/main.rs @@ -100,7 +100,7 @@ fn main() { if !args.is_present("no-vcs-ignore") { let gitignore_path = cwd.join(".gitignore"); if gitignore_path.exists() { - debug!("Found .gitignore file: {}", gitignore_path.to_str().unwrap()); + debug!("Found .gitignore file: {:?}", gitignore_path); gitignore_file = gitignore::parse(&gitignore_path).ok(); } diff --git a/src/notification_filter.rs b/src/notification_filter.rs index a09b910..15eef73 100644 --- a/src/notification_filter.rs +++ b/src/notification_filter.rs @@ -19,18 +19,6 @@ pub enum NotificationError { Io(io::Error) } -impl From for NotificationError { - fn from(err: io::Error) -> NotificationError { - NotificationError::Io(err) - } -} - -impl From for NotificationError { - fn from(err: PatternError) -> NotificationError { - NotificationError::BadPattern(err) - } -} - impl NotificationFilter { pub fn new(current_dir: &Path, ignore_file: Option) -> Result { let canonicalized = try!(current_dir.canonicalize()); @@ -43,18 +31,14 @@ impl NotificationFilter { }) } - pub fn add_extension(&mut self, extension: &str) -> Result<(), NotificationError> { - let mut pattern = String::new(); - - for ext in extension.split(",") { - pattern.clear(); - pattern.push_str("*"); - - if !ext.starts_with(".") { - pattern.push_str("."); - } - pattern.push_str(ext); + pub fn add_extension(&mut self, extensions: &str) -> Result<(), NotificationError> { + let patterns: Vec = extensions + .split(",") + .filter(|ext| !ext.is_empty()) + .map(|ext| format!("*.{}", ext.replace(".", ""))) + .collect(); + for pattern in patterns { try!(self.add_filter(&pattern)); } @@ -65,6 +49,8 @@ impl NotificationFilter { let compiled = try!(self.pattern_for(pattern)); self.filters.push(compiled); + debug!("Adding filter: {}", pattern); + Ok(()) } @@ -72,6 +58,8 @@ impl NotificationFilter { let compiled = try!(self.pattern_for(pattern)); self.ignores.push(compiled); + debug!("Adding ignore: {}", pattern); + Ok(()) } @@ -114,3 +102,15 @@ impl NotificationFilter { self.filters.len() > 0 } } + +impl From for NotificationError { + fn from(err: io::Error) -> NotificationError { + NotificationError::Io(err) + } +} + +impl From for NotificationError { + fn from(err: PatternError) -> NotificationError { + NotificationError::BadPattern(err) + } +}