Formatting

This commit is contained in:
Félix Saparelli 2021-04-11 04:32:58 +12:00
parent cdd8a7b91a
commit 5753e7773f
No known key found for this signature in database
GPG Key ID: B948C4BAE44FC474
5 changed files with 29 additions and 21 deletions

View File

@ -1,13 +1,13 @@
use clap::{App, Arg, value_t, values_t, crate_version}; use clap::{crate_version, value_t, values_t, App, Arg};
use log::LevelFilter; use log::LevelFilter;
use std::{ use std::{
ffi::OsString, ffi::OsString,
path::{PathBuf, MAIN_SEPARATOR}, path::{PathBuf, MAIN_SEPARATOR},
}; };
use crate::{error, Shell};
use crate::config::{Config, ConfigBuilder}; use crate::config::{Config, ConfigBuilder};
use crate::run::OnBusyUpdate; use crate::run::OnBusyUpdate;
use crate::{error, Shell};
pub fn get_args() -> error::Result<(Config, LevelFilter)> { pub fn get_args() -> error::Result<(Config, LevelFilter)> {
get_args_impl(None::<&[&str]>) get_args_impl(None::<&[&str]>)
@ -146,7 +146,8 @@ where
let mut builder = ConfigBuilder::default(); let mut builder = ConfigBuilder::default();
let cmd: Vec<String> = values_t!(args.values_of("command"), String).map_err(|err| err.to_string())?; let cmd: Vec<String> =
values_t!(args.values_of("command"), String).map_err(|err| err.to_string())?;
builder.cmd(cmd); builder.cmd(cmd);
let paths: Vec<PathBuf> = values_t!(args.values_of("path"), String) let paths: Vec<PathBuf> = values_t!(args.values_of("path"), String)
@ -167,7 +168,8 @@ where
let mut filters = values_t!(args.values_of("filter"), String).unwrap_or_else(|_| Vec::new()); let mut filters = values_t!(args.values_of("filter"), String).unwrap_or_else(|_| Vec::new());
if let Some(extensions) = args.values_of("extensions") { if let Some(extensions) = args.values_of("extensions") {
for exts in extensions { // TODO: refactor with flatten() for exts in extensions {
// TODO: refactor with flatten()
filters.extend(exts.split(',').filter_map(|ext| { filters.extend(exts.split(',').filter_map(|ext| {
if ext.is_empty() { if ext.is_empty() {
None None
@ -219,7 +221,7 @@ where
b"queue" => OnBusyUpdate::Queue, b"queue" => OnBusyUpdate::Queue,
b"restart" => OnBusyUpdate::Restart, b"restart" => OnBusyUpdate::Restart,
b"signal" => OnBusyUpdate::Signal, b"signal" => OnBusyUpdate::Signal,
_ => unreachable!("clap restricts on-busy-updates values") _ => unreachable!("clap restricts on-busy-updates values"),
} }
} else { } else {
// will become DoNothing in v2.0 // will become DoNothing in v2.0

View File

@ -7,13 +7,16 @@ use crate::config::{Config, ConfigBuilder};
#[deprecated(since = "1.15.0", note = "Config has moved to config::Config")] #[deprecated(since = "1.15.0", note = "Config has moved to config::Config")]
pub type Args = Config; pub type Args = Config;
#[deprecated(since = "1.15.0", note = "ConfigBuilder has moved to config::ConfigBuilder")] #[deprecated(
since = "1.15.0",
note = "ConfigBuilder has moved to config::ConfigBuilder"
)]
pub type ArgsBuilder = ConfigBuilder; pub type ArgsBuilder = ConfigBuilder;
/// Clear the screen. /// Clear the screen.
#[cfg(target_family = "windows")] #[cfg(target_family = "windows")]
pub fn clear_screen() { pub fn clear_screen() {
// TODO: clearscreen with powershell? // TODO: clearscreen with powershell?
let _ = Command::new("cmd") let _ = Command::new("cmd")
.arg("/c") .arg("/c")
.arg("tput reset || cls") .arg("tput reset || cls")
@ -23,12 +26,18 @@ pub fn clear_screen() {
/// Clear the screen. /// Clear the screen.
#[cfg(target_family = "unix")] #[cfg(target_family = "unix")]
pub fn clear_screen() { pub fn clear_screen() {
// TODO: clear screen via control codes instead // TODO: clear screen via control codes instead
let _ = Command::new("tput").arg("reset").status(); let _ = Command::new("tput").arg("reset").status();
} }
#[deprecated(since = "1.15.0", note = "this will be removed from the library API. use the builder")] #[deprecated(
since = "1.15.0",
note = "this will be removed from the library API. use the builder"
)]
pub use crate::args::get_args; pub use crate::args::get_args;
#[deprecated(since = "1.15.0", note = "this will be removed from the library API. use the builder")] #[deprecated(
since = "1.15.0",
note = "this will be removed from the library API. use the builder"
)]
pub use crate::args::get_args_from; pub use crate::args::get_args_from;

View File

@ -9,10 +9,7 @@
//! //!
//! [watchexec]: https://github.com/watchexec/watchexec //! [watchexec]: https://github.com/watchexec/watchexec
#![warn( #![warn(clippy::option_unwrap_used, clippy::result_unwrap_used)]
clippy::option_unwrap_used,
clippy::result_unwrap_used,
)]
#[macro_use] #[macro_use]
extern crate derive_builder; extern crate derive_builder;
@ -40,5 +37,8 @@ pub use run::{run, watch, Handler};
#[deprecated(since = "1.15.0", note = "Config has moved to config::Config")] #[deprecated(since = "1.15.0", note = "Config has moved to config::Config")]
pub type Args = config::Config; pub type Args = config::Config;
#[deprecated(since = "1.15.0", note = "ConfigBuilder has moved to config::ConfigBuilder")] #[deprecated(
since = "1.15.0",
note = "ConfigBuilder has moved to config::ConfigBuilder"
)]
pub type ArgsBuilder = config::ConfigBuilder; pub type ArgsBuilder = config::ConfigBuilder;

View File

@ -1,7 +1,7 @@
use std::io::Write; use std::io::Write;
// until args.rs is removed from the lib // until args.rs is removed from the lib
pub(crate) use watchexec::{error, config, run, Shell}; pub(crate) use watchexec::{config, error, run, Shell};
mod args; mod args;

View File

@ -1,4 +1,4 @@
use crate::cli::{clear_screen}; use crate::cli::clear_screen;
use crate::config::Config; use crate::config::Config;
use crate::error::{Error, Result}; use crate::error::{Error, Result};
use crate::gitignore; use crate::gitignore;
@ -231,10 +231,7 @@ impl Handler for ExecHandler {
fn on_update(&self, ops: &[PathOp]) -> Result<bool> { fn on_update(&self, ops: &[PathOp]) -> Result<bool> {
let signal = self.signal.unwrap_or(Signal::SIGTERM); let signal = self.signal.unwrap_or(Signal::SIGTERM);
match ( match (self.has_running_process(), self.args.on_busy_update) {
self.has_running_process(),
self.args.on_busy_update,
) {
// If nothing is running, start the command // If nothing is running, start the command
(false, _) => { (false, _) => {
self.spawn(ops)?; self.spawn(ops)?;