Document the semantics of the Shell variants

This commit is contained in:
Félix Saparelli 2021-04-17 01:20:30 +12:00
parent 3c26e3987c
commit a2078e3703
2 changed files with 47 additions and 5 deletions

View file

@ -24,54 +24,75 @@ use crate::run::OnBusyUpdate;
#[builder(build_fn(validate = "Self::validate"))] #[builder(build_fn(validate = "Self::validate"))]
#[non_exhaustive] #[non_exhaustive]
pub struct Config { pub struct Config {
/// Command to execute in popen3 format (first program, rest arguments). /// Command to execute.
///
/// When `shell` is [`Shell::None`], this is expected to be in “popen3”
/// format: first program, rest arguments. Otherwise, all elements will be
/// joined together with a single space and passed to the shell. More
/// control can then be obtained by providing a 1-element vec, and doing
/// your own joining and/or escaping there.
pub cmd: Vec<String>, pub cmd: Vec<String>,
/// List of paths to watch for changes. /// List of paths to watch for changes.
pub paths: Vec<PathBuf>, pub paths: Vec<PathBuf>,
/// Positive filters (trigger only on matching changes). Glob format. /// Positive filters (trigger only on matching changes). Glob format.
#[builder(default)] #[builder(default)]
pub filters: Vec<String>, pub filters: Vec<String>,
/// Negative filters (do not trigger on matching changes). Glob format. /// Negative filters (do not trigger on matching changes). Glob format.
#[builder(default)] #[builder(default)]
pub ignores: Vec<String>, pub ignores: Vec<String>,
/// Clear the screen before each run. /// Clear the screen before each run.
#[builder(default)] #[builder(default)]
pub clear_screen: bool, pub clear_screen: bool,
/// If Some, send that signal (e.g. SIGHUP) to the command on change. /// If Some, send that signal (e.g. SIGHUP) to the command on change.
#[builder(default)] #[builder(default)]
pub signal: Option<String>, pub signal: Option<String>,
/// Specify what to do when receiving updates while the command is running. /// Specify what to do when receiving updates while the command is running.
#[builder(default)] #[builder(default)]
pub on_busy_update: OnBusyUpdate, pub on_busy_update: OnBusyUpdate,
/// Interval to debounce the changes. /// Interval to debounce the changes.
#[builder(default = "Duration::from_millis(150)")] #[builder(default = "Duration::from_millis(150)")]
pub debounce: Duration, pub debounce: Duration,
/// Run the commands right after starting. /// Run the commands right after starting.
#[builder(default = "true")] #[builder(default = "true")]
pub run_initially: bool, pub run_initially: bool,
/// Specify the shell to use. /// Specify the shell to use.
#[builder(default)] #[builder(default)]
pub shell: Shell, pub shell: Shell,
/// Ignore metadata changes. /// Ignore metadata changes.
#[builder(default)] #[builder(default)]
pub no_meta: bool, pub no_meta: bool,
/// Do not set WATCHEXEC_*_PATH environment variables for the process. /// Do not set WATCHEXEC_*_PATH environment variables for the process.
#[builder(default)] #[builder(default)]
pub no_environment: bool, pub no_environment: bool,
/// Skip auto-loading .gitignore files /// Skip auto-loading .gitignore files
#[builder(default)] #[builder(default)]
pub no_vcs_ignore: bool, pub no_vcs_ignore: bool,
/// Skip auto-loading .ignore files /// Skip auto-loading .ignore files
#[builder(default)] #[builder(default)]
pub no_ignore: bool, pub no_ignore: bool,
/// For testing only, always set to false. /// For testing only, always set to false.
#[builder(setter(skip))] #[builder(setter(skip), default)]
#[builder(default)]
#[doc(hidden)] #[doc(hidden)]
pub once: bool, pub once: bool,
/// Force using the polling backend. /// Force using the polling backend.
#[builder(default)] #[builder(default)]
pub poll: bool, pub poll: bool,
/// Interval for polling. /// Interval for polling.
#[builder(default = "Duration::from_secs(1)")] #[builder(default = "Duration::from_secs(1)")]
pub poll_interval: Duration, pub poll_interval: Duration,

View file

@ -2,20 +2,41 @@
use crate::error::Result; use crate::error::Result;
use crate::pathop::PathOp; use crate::pathop::PathOp;
use std::collections::{HashMap, HashSet}; use std::{collections::{HashMap, HashSet},
use std::path::PathBuf; path::PathBuf,
process::Command};
/// Shell to use to run commands. /// Shell to use to run commands.
/// ///
/// `Cmd` and `Powershell` are special-cased because they have different calling /// `Cmd` and `Powershell` are special-cased because they have different calling
/// conventions. Also `Cmd` is only available in Windows, while `Powershell` is /// conventions. Also `Cmd` is only available in Windows, while `Powershell` is
/// also available on unices (provided the end-user has it installed, of course). /// also available on unices (provided the end-user has it installed, of course).
///
/// See [`Config.cmd`][crate::config::Config] for the semantics of `None` vs the
/// other options.
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub enum Shell { pub enum Shell {
/// Use no shell, and execute the command directly.
None, None,
/// Use the given string as a unix shell invocation.
///
/// This means two things:
/// - the program is invoked with `-c` followed by the command, and
Unix(String), Unix(String),
/// Use the Windows CMD.EXE shell.
///
/// This is invoked with `/C` followed by the command.
#[cfg(windows)] #[cfg(windows)]
Cmd, Cmd,
/// Use Powershell, on Windows or elsewhere.
///
/// This is invoked with `-Command` followed by the command.
///
/// This is preferred over `Unix("pwsh")`, though that will also work
/// on unices due to Powershell supporting the `-c` short option.
Powershell, Powershell,
} }