mirror of
https://github.com/watchexec/watchexec.git
synced 2024-09-29 22:51:33 +02:00
[meta] Run formatter
This commit is contained in:
parent
3a6c6b36b2
commit
6f473bcd87
17
src/cli.rs
17
src/cli.rs
@ -1,6 +1,11 @@
|
|||||||
use clap::{App, Arg, Error};
|
use clap::{App, Arg, Error};
|
||||||
use 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)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
@ -36,13 +41,17 @@ pub fn get_args() -> error::Result<Args> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_args_from<I, T>(from: I) -> error::Result<Args>
|
pub fn get_args_from<I, T>(from: I) -> error::Result<Args>
|
||||||
where I: IntoIterator<Item=T>, T: Into<OsString> + Clone
|
where
|
||||||
|
I: IntoIterator<Item = T>,
|
||||||
|
T: Into<OsString> + Clone,
|
||||||
{
|
{
|
||||||
get_args_impl(Some(from))
|
get_args_impl(Some(from))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_args_impl<I, T>(from: Option<I>) -> error::Result<Args>
|
fn get_args_impl<I, T>(from: Option<I>) -> error::Result<Args>
|
||||||
where I: IntoIterator<Item=T>, T: Into<OsString> + Clone
|
where
|
||||||
|
I: IntoIterator<Item = T>,
|
||||||
|
T: Into<OsString> + Clone,
|
||||||
{
|
{
|
||||||
let app = App::new("watchexec")
|
let app = App::new("watchexec")
|
||||||
.version(crate_version!())
|
.version(crate_version!())
|
||||||
@ -130,7 +139,7 @@ where I: IntoIterator<Item=T>, T: Into<OsString> + Clone
|
|||||||
|
|
||||||
let args = match from {
|
let args = match from {
|
||||||
None => app.get_matches(),
|
None => app.get_matches(),
|
||||||
Some(i) => app.get_matches_from(i)
|
Some(i) => app.get_matches_from(i),
|
||||||
};
|
};
|
||||||
|
|
||||||
let cmd: Vec<String> = values_t!(args.values_of("command"), String)?;
|
let cmd: Vec<String> = values_t!(args.values_of("command"), String)?;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
extern crate watchexec;
|
extern crate watchexec;
|
||||||
|
|
||||||
use watchexec::{cli, error, run};
|
use watchexec::{cli, error, run};
|
||||||
|
|
||||||
fn main() -> error::Result<()> {
|
fn main() -> error::Result<()> {
|
||||||
|
@ -81,11 +81,8 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_filename() {
|
fn test_filename() {
|
||||||
let filter = NotificationFilter::new(
|
let filter =
|
||||||
&[],
|
NotificationFilter::new(&[], &["test.json".into()], gitignore::load(&[])).unwrap();
|
||||||
&["test.json".into()],
|
|
||||||
gitignore::load(&[]),
|
|
||||||
).unwrap();
|
|
||||||
|
|
||||||
assert!(filter.is_excluded(&Path::new("/path/to/test.json")));
|
assert!(filter.is_excluded(&Path::new("/path/to/test.json")));
|
||||||
assert!(filter.is_excluded(&Path::new("test.json")));
|
assert!(filter.is_excluded(&Path::new("test.json")));
|
||||||
@ -104,7 +101,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_multiple_ignores() {
|
fn test_multiple_ignores() {
|
||||||
let ignores = &["*.rs".into(), "*.toml".into()];
|
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("hello.rs")));
|
||||||
assert!(filter.is_excluded(&Path::new("Cargo.toml")));
|
assert!(filter.is_excluded(&Path::new("Cargo.toml")));
|
||||||
@ -114,8 +111,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_ignores_take_precedence() {
|
fn test_ignores_take_precedence() {
|
||||||
let ignores = &["*.rs".into(), "*.toml".into()];
|
let ignores = &["*.rs".into(), "*.toml".into()];
|
||||||
let filter =
|
let filter = NotificationFilter::new(ignores, ignores, gitignore::load(&[])).unwrap();
|
||||||
NotificationFilter::new(ignores, ignores, gitignore::load(&[])).unwrap();
|
|
||||||
|
|
||||||
assert!(filter.is_excluded(&Path::new("hello.rs")));
|
assert!(filter.is_excluded(&Path::new("hello.rs")));
|
||||||
assert!(filter.is_excluded(&Path::new("Cargo.toml")));
|
assert!(filter.is_excluded(&Path::new("Cargo.toml")));
|
||||||
|
@ -114,7 +114,7 @@ mod imp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
command
|
command
|
||||||
.before_exec(|| setsid().map_err(from_nix_error).map(|_|()))
|
.before_exec(|| setsid().map_err(from_nix_error).map(|_| ()))
|
||||||
.spawn()
|
.spawn()
|
||||||
.and_then(|p| {
|
.and_then(|p| {
|
||||||
Ok(Process {
|
Ok(Process {
|
||||||
|
41
src/run.rs
41
src/run.rs
@ -1,13 +1,6 @@
|
|||||||
use std::collections::HashMap;
|
use cli::{clear_screen, Args};
|
||||||
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 env_logger;
|
use env_logger;
|
||||||
use error::{Error, Result};
|
use error::Result;
|
||||||
use gitignore;
|
use gitignore;
|
||||||
use log;
|
use log;
|
||||||
use notification_filter::NotificationFilter;
|
use notification_filter::NotificationFilter;
|
||||||
@ -16,6 +9,15 @@ use notify;
|
|||||||
use pathop::PathOp;
|
use pathop::PathOp;
|
||||||
use process::{self, Process};
|
use process::{self, Process};
|
||||||
use signal::{self, Signal};
|
use signal::{self, Signal};
|
||||||
|
use std::{
|
||||||
|
collections::HashMap,
|
||||||
|
io::Write,
|
||||||
|
sync::{
|
||||||
|
mpsc::{channel, Receiver},
|
||||||
|
Arc, RwLock,
|
||||||
|
},
|
||||||
|
time::Duration,
|
||||||
|
};
|
||||||
use watcher::{Event, Watcher};
|
use watcher::{Event, Watcher};
|
||||||
|
|
||||||
fn init_logger(debug: bool) {
|
fn init_logger(debug: bool) {
|
||||||
@ -34,7 +36,9 @@ fn init_logger(debug: bool) {
|
|||||||
|
|
||||||
pub trait Handler {
|
pub trait Handler {
|
||||||
/// Initialises the `Handler` with a copy of the arguments.
|
/// Initialises the `Handler` with a copy of the arguments.
|
||||||
fn new(args: Args) -> Result<Self> where Self: Sized;
|
fn new(args: Args) -> Result<Self>
|
||||||
|
where
|
||||||
|
Self: Sized;
|
||||||
|
|
||||||
/// Called through a manual request, such as an initial run.
|
/// 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
|
/// Given an argument structure and a `Handler` type, starts the watcher
|
||||||
/// loop (blocking until done).
|
/// loop (blocking until done).
|
||||||
pub fn watch<H>(args: Args) -> Result<()> where H: Handler {
|
pub fn watch<H>(args: Args) -> Result<()>
|
||||||
|
where
|
||||||
|
H: Handler,
|
||||||
|
{
|
||||||
init_logger(args.debug);
|
init_logger(args.debug);
|
||||||
let mut handler = H::new(args.clone())?;
|
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<bool> {
|
fn on_manual(&mut self) -> Result<bool> {
|
||||||
let mut guard = self.child_process.write()?;
|
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)
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
|
use notify::{raw_watcher, PollWatcher, RecommendedWatcher, RecursiveMode};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
|
|
||||||
use notify::{raw_watcher, PollWatcher, RecommendedWatcher, RecursiveMode};
|
|
||||||
|
|
||||||
/// Thin wrapper over the notify crate
|
/// Thin wrapper over the notify crate
|
||||||
///
|
///
|
||||||
/// `PollWatcher` and `RecommendedWatcher` are distinct types, but watchexec
|
/// `PollWatcher` and `RecommendedWatcher` are distinct types, but watchexec
|
||||||
|
Loading…
Reference in New Issue
Block a user