From 6f473bcd87ce2324f15c7ff2bb5807dac36f96eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sat, 26 Jan 2019 15:15:27 +1300 Subject: [PATCH] [meta] Run formatter --- src/cli.rs | 17 ++++++++++++---- src/main.rs | 1 + src/notification_filter.rs | 12 ++++------- src/process.rs | 2 +- src/run.rs | 41 ++++++++++++++++++++++++++------------ src/watcher.rs | 3 +-- 6 files changed, 48 insertions(+), 28 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index e02aee8..1e90f8d 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,6 +1,11 @@ use clap::{App, Arg, Error}; use error; -use std::{ffi::OsString, fs::canonicalize, path::{MAIN_SEPARATOR, PathBuf}, process::Command}; +use std::{ + ffi::OsString, + fs::canonicalize, + path::{PathBuf, MAIN_SEPARATOR}, + process::Command, +}; #[derive(Clone, Debug)] pub struct Args { @@ -36,13 +41,17 @@ pub fn get_args() -> error::Result { } pub fn get_args_from(from: I) -> error::Result -where I: IntoIterator, T: Into + Clone +where + I: IntoIterator, + T: Into + Clone, { get_args_impl(Some(from)) } fn get_args_impl(from: Option) -> error::Result -where I: IntoIterator, T: Into + Clone +where + I: IntoIterator, + T: Into + Clone, { let app = App::new("watchexec") .version(crate_version!()) @@ -130,7 +139,7 @@ where I: IntoIterator, T: Into + Clone let args = match from { None => app.get_matches(), - Some(i) => app.get_matches_from(i) + Some(i) => app.get_matches_from(i), }; let cmd: Vec = values_t!(args.values_of("command"), String)?; diff --git a/src/main.rs b/src/main.rs index f6f70ff..7834023 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ extern crate watchexec; + use watchexec::{cli, error, run}; fn main() -> error::Result<()> { diff --git a/src/notification_filter.rs b/src/notification_filter.rs index 3268c82..632772b 100644 --- a/src/notification_filter.rs +++ b/src/notification_filter.rs @@ -81,11 +81,8 @@ mod tests { #[test] fn test_filename() { - let filter = NotificationFilter::new( - &[], - &["test.json".into()], - gitignore::load(&[]), - ).unwrap(); + let filter = + NotificationFilter::new(&[], &["test.json".into()], gitignore::load(&[])).unwrap(); assert!(filter.is_excluded(&Path::new("/path/to/test.json"))); assert!(filter.is_excluded(&Path::new("test.json"))); @@ -104,7 +101,7 @@ mod tests { #[test] fn test_multiple_ignores() { let ignores = &["*.rs".into(), "*.toml".into()]; - let filter = NotificationFilter::new(&[], ignores, gitignore::load(&vec![])).unwrap(); + let filter = NotificationFilter::new(&[], ignores, gitignore::load(&[])).unwrap(); assert!(filter.is_excluded(&Path::new("hello.rs"))); assert!(filter.is_excluded(&Path::new("Cargo.toml"))); @@ -114,8 +111,7 @@ mod tests { #[test] fn test_ignores_take_precedence() { let ignores = &["*.rs".into(), "*.toml".into()]; - let filter = - NotificationFilter::new(ignores, ignores, gitignore::load(&[])).unwrap(); + let filter = NotificationFilter::new(ignores, ignores, gitignore::load(&[])).unwrap(); assert!(filter.is_excluded(&Path::new("hello.rs"))); assert!(filter.is_excluded(&Path::new("Cargo.toml"))); diff --git a/src/process.rs b/src/process.rs index ee4c054..0249501 100644 --- a/src/process.rs +++ b/src/process.rs @@ -114,7 +114,7 @@ mod imp { } command - .before_exec(|| setsid().map_err(from_nix_error).map(|_|())) + .before_exec(|| setsid().map_err(from_nix_error).map(|_| ())) .spawn() .and_then(|p| { Ok(Process { diff --git a/src/run.rs b/src/run.rs index fa8048a..dcc414b 100644 --- a/src/run.rs +++ b/src/run.rs @@ -1,13 +1,6 @@ -use std::collections::HashMap; -use std::fs::canonicalize; -use std::io::Write; -use std::sync::mpsc::{channel, Receiver}; -use std::sync::{Arc, RwLock}; -use std::time::Duration; - -use cli::{Args, clear_screen}; +use cli::{clear_screen, Args}; use env_logger; -use error::{Error, Result}; +use error::Result; use gitignore; use log; use notification_filter::NotificationFilter; @@ -16,6 +9,15 @@ use notify; use pathop::PathOp; use process::{self, Process}; use signal::{self, Signal}; +use std::{ + collections::HashMap, + io::Write, + sync::{ + mpsc::{channel, Receiver}, + Arc, RwLock, + }, + time::Duration, +}; use watcher::{Event, Watcher}; fn init_logger(debug: bool) { @@ -34,7 +36,9 @@ fn init_logger(debug: bool) { pub trait Handler { /// Initialises the `Handler` with a copy of the arguments. - fn new(args: Args) -> Result where Self: Sized; + fn new(args: Args) -> Result + where + Self: Sized; /// Called through a manual request, such as an initial run. /// @@ -67,7 +71,10 @@ pub trait Handler { /// /// Given an argument structure and a `Handler` type, starts the watcher /// loop (blocking until done). -pub fn watch(args: Args) -> Result<()> where H: Handler { +pub fn watch(args: Args) -> Result<()> +where + H: Handler, +{ init_logger(args.debug); let mut handler = H::new(args.clone())?; @@ -160,12 +167,20 @@ impl Handler for ExecHandler { } }); - Ok(Self { args, signal, child_process }) + Ok(Self { + args, + signal, + child_process, + }) } fn on_manual(&mut self) -> Result { let mut guard = self.child_process.write()?; - *guard = Some(process::spawn(&self.args.cmd, Vec::new(), self.args.no_shell)); + *guard = Some(process::spawn( + &self.args.cmd, + Vec::new(), + self.args.no_shell, + )); Ok(true) } diff --git a/src/watcher.rs b/src/watcher.rs index a52321a..761301f 100644 --- a/src/watcher.rs +++ b/src/watcher.rs @@ -1,8 +1,7 @@ +use notify::{raw_watcher, PollWatcher, RecommendedWatcher, RecursiveMode}; use std::path::PathBuf; use std::sync::mpsc::Sender; -use notify::{raw_watcher, PollWatcher, RecommendedWatcher, RecursiveMode}; - /// Thin wrapper over the notify crate /// /// `PollWatcher` and `RecommendedWatcher` are distinct types, but watchexec