Canonicalize watched paths
This commit is contained in:
parent
cd8e43baaf
commit
c990c9c4d4
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "watchexec"
|
name = "watchexec"
|
||||||
version = "0.10.0"
|
version = "0.10.1"
|
||||||
authors = ["Matt Green <mattgreenrocks@gmail.com>"]
|
authors = ["Matt Green <mattgreenrocks@gmail.com>"]
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -72,7 +72,7 @@ fn wait(rx: &Receiver<Event>, filter: &NotificationFilter, verbose: bool) -> Res
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = App::new("watchexec")
|
let args = App::new("watchexec")
|
||||||
.version("0.10.0")
|
.version("0.10.1")
|
||||||
.about("Execute commands when watched files change")
|
.about("Execute commands when watched files change")
|
||||||
.arg(Arg::with_name("path")
|
.arg(Arg::with_name("path")
|
||||||
.help("Path to watch")
|
.help("Path to watch")
|
||||||
|
@ -124,7 +124,7 @@ fn main() {
|
||||||
let verbose = args.is_present("verbose");
|
let verbose = args.is_present("verbose");
|
||||||
|
|
||||||
let cwd = env::current_dir().unwrap();
|
let cwd = env::current_dir().unwrap();
|
||||||
let mut filter = NotificationFilter::new(&cwd);
|
let mut filter = NotificationFilter::new(&cwd).expect("unable to create notification filter");
|
||||||
|
|
||||||
// Add default ignore list
|
// Add default ignore list
|
||||||
let dotted_dirs = Path::new(".*").join("*");
|
let dotted_dirs = Path::new(".*").join("*");
|
||||||
|
@ -156,7 +156,13 @@ fn main() {
|
||||||
|
|
||||||
let paths = args.values_of("path").unwrap();
|
let paths = args.values_of("path").unwrap();
|
||||||
for path in paths {
|
for path in paths {
|
||||||
watcher.watch(path).expect("unable to watch path");
|
match Path::new(path).canonicalize() {
|
||||||
|
Ok(canonicalized) => watcher.watch(canonicalized).expect("unable to watch path"),
|
||||||
|
Err(_) => {
|
||||||
|
println!("invalid path: {}", path);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let cmd_parts: Vec<&str> = args.values_of("command").unwrap().collect();
|
let cmd_parts: Vec<&str> = args.values_of("command").unwrap().collect();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
extern crate glob;
|
extern crate glob;
|
||||||
|
|
||||||
|
use std::io;
|
||||||
use std::path::{Path,PathBuf};
|
use std::path::{Path,PathBuf};
|
||||||
|
|
||||||
use self::glob::{Pattern,PatternError};
|
use self::glob::{Pattern,PatternError};
|
||||||
|
@ -10,16 +11,36 @@ pub struct NotificationFilter {
|
||||||
ignores: Vec<Pattern>
|
ignores: Vec<Pattern>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum NotificationError {
|
||||||
|
BadPattern(PatternError),
|
||||||
|
Io(io::Error)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<io::Error> for NotificationError {
|
||||||
|
fn from(err: io::Error) -> NotificationError {
|
||||||
|
NotificationError::Io(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<PatternError> for NotificationError {
|
||||||
|
fn from(err: PatternError) -> NotificationError {
|
||||||
|
NotificationError::BadPattern(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl NotificationFilter {
|
impl NotificationFilter {
|
||||||
pub fn new(current_dir: &Path) -> NotificationFilter {
|
pub fn new(current_dir: &Path) -> Result<NotificationFilter, io::Error> {
|
||||||
NotificationFilter {
|
let canonicalized = try!(current_dir.canonicalize());
|
||||||
cwd: current_dir.to_path_buf(),
|
|
||||||
|
Ok(NotificationFilter {
|
||||||
|
cwd: canonicalized,
|
||||||
filters: vec![],
|
filters: vec![],
|
||||||
ignores: vec![]
|
ignores: vec![]
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_extension(&mut self, extension: &str) -> Result<(), PatternError> {
|
pub fn add_extension(&mut self, extension: &str) -> Result<(), NotificationError> {
|
||||||
let mut pattern = String::new();
|
let mut pattern = String::new();
|
||||||
|
|
||||||
for ext in extension.split(",") {
|
for ext in extension.split(",") {
|
||||||
|
@ -37,14 +58,14 @@ impl NotificationFilter {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_filter(&mut self, pattern: &str) -> Result<(), PatternError> {
|
pub fn add_filter(&mut self, pattern: &str) -> Result<(), NotificationError> {
|
||||||
let compiled = try!(self.pattern_for(pattern));
|
let compiled = try!(self.pattern_for(pattern));
|
||||||
self.filters.push(compiled);
|
self.filters.push(compiled);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_ignore(&mut self, pattern: &str) -> Result<(), PatternError> {
|
pub fn add_ignore(&mut self, pattern: &str) -> Result<(), NotificationError> {
|
||||||
let compiled = try!(self.pattern_for(pattern));
|
let compiled = try!(self.pattern_for(pattern));
|
||||||
self.ignores.push(compiled);
|
self.ignores.push(compiled);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue