add --no-environment switch to fix #78
This commit is contained in:
parent
6f6fb0ceb2
commit
524812028d
|
@ -13,6 +13,7 @@ args=(
|
|||
'(-h --help)'{-h,--help}'[Prints help information]'
|
||||
'(-k --kill)'{-k,--kill}'[Send SIGKILL to child processes (deprecated, use -s SIGKILL instead)]'
|
||||
'(-n --no-shell)'{-n,--no-shell}'[Do not wrap command in ''sh -c'' resp. ''cmd.exe /C'']'
|
||||
'--no-environment[Do not set WATCHEXEC_*_PATH environment variables for child process]'
|
||||
'(-p --postpone)'{-p,--postpone}'[Wait until first change to execute command]'
|
||||
'(-r --restart)'{-r,--restart}'[Restart the process if it''s still running]'
|
||||
'(-V --version)'{-V,--version}'[Prints version information]'
|
||||
|
|
|
@ -90,6 +90,7 @@
|
|||
<dt><code>-f</code>, <code>--filter</code> <var>pattern</var></dt><dd><p>Ignores modifications from paths that do not match <var>pattern</var>. This option can be specified multiple times, where a match on any given pattern causes the path to trigger <var>command</var>.</p></dd>
|
||||
<dt><code>-s</code>, <code>--signal</code></dt><dd><p>Sends the specified signal (e.g. <code>SIGKILL</code>) to the child process. Defaults to <code>SIGTERM</code>.</p></dd>
|
||||
<dt><code>-n</code>, <code>--no-shell</code></dt><dd><p>Execute command directly, do not wrap it in <code>sh -c</code> resp. <code>cmd.exe /C</code>. This is especially useful in combination with <code>--signal</code>, as the signal is then send directly to the specified command. While <code>--no-shell</code> is a little more performant than the default, it prevents using shell-features like pipes and redirects.</p></dd>
|
||||
<dt><code>--no-environment</code></dt><dd><p>Do not set WATCHEXEC_*_PATH environment variables for child process.</p></dd>
|
||||
<dt><code>-i</code>, <code>--ignore</code> <var>pattern</var></dt><dd><p>Ignores modifications from paths that match <var>pattern</var>. This option can be specified multiple times, and a match on any pattern causes the path to be ignored.</p></dd>
|
||||
<dt><code>-w</code>, <code>--watch</code> <var>path</var></dt><dd><p>Monitor a specific path for changes. By default, the current working directory is watched. This may be specified multiple times, where a change in any watched directory (and subdirectories) causes <var>command</var> to be executed.</p></dd>
|
||||
<dt><code>-r</code>, <code>--restart</code></dt><dd><p>Terminates the child process group if it is still running when subsequent file modifications are detected. By default, sends <code>SIGTERM</code>; use <code>--kill</code> to send <code>SIGKILL</code>.</p></dd>
|
||||
|
|
|
@ -28,6 +28,9 @@ Sends the specified signal (e.g. `SIGKILL`) to the child process. Defaults to `S
|
|||
* `-n`, `--no-shell`:
|
||||
Execute command directly, do not wrap it in `sh -c` resp. `cmd.exe /C`. This is especially useful in combination with `--signal`, as the signal is then send directly to the specified command. While `--no-shell` is a little more performant than the default, it prevents using shell-features like pipes and redirects.
|
||||
|
||||
* `--no-environment`:
|
||||
Do not set WATCHEXEC_*_PATH environment variables for child process.
|
||||
|
||||
* `-i`, `--ignore` <pattern>:
|
||||
Ignores modifications from paths that match <pattern>. This option can be specified multiple times, and a match on any pattern causes the path to be ignored.
|
||||
|
||||
|
|
|
@ -58,6 +58,9 @@ pub struct Args {
|
|||
/// Do not wrap the commands in a shell.
|
||||
#[builder(default)]
|
||||
pub no_shell: bool,
|
||||
/// Do not set WATCHEXEC_*_PATH environment variables for child process.
|
||||
#[builder(default)]
|
||||
pub no_environment: bool,
|
||||
/// Skip auto-loading .gitignore files
|
||||
#[builder(default)]
|
||||
pub no_vcs_ignore: bool,
|
||||
|
@ -207,6 +210,9 @@ where
|
|||
.help("Do not wrap command in 'sh -c' resp. 'cmd.exe /C'")
|
||||
.short("n")
|
||||
.long("no-shell"))
|
||||
.arg(Arg::with_name("no-environment")
|
||||
.help("Do not set WATCHEXEC_*_PATH environment variables for child process")
|
||||
.long("no-environment"))
|
||||
.arg(Arg::with_name("once").short("1").hidden(true))
|
||||
.arg(Arg::with_name("watch-when-idle")
|
||||
.help("Ignore events while the process is still running")
|
||||
|
@ -302,6 +308,7 @@ where
|
|||
debug: args.is_present("verbose"),
|
||||
run_initially: !args.is_present("postpone"),
|
||||
no_shell: args.is_present("no-shell"),
|
||||
no_environment: args.is_present("no-environment"),
|
||||
no_vcs_ignore: args.is_present("no-vcs-ignore"),
|
||||
no_ignore: args.is_present("no-ignore"),
|
||||
once: args.is_present("once"),
|
||||
|
|
|
@ -5,8 +5,8 @@ use crate::pathop::PathOp;
|
|||
use std::collections::{HashMap, HashSet};
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub fn spawn(cmd: &[String], updated_paths: &[PathOp], no_shell: bool) -> Result<Process> {
|
||||
self::imp::Process::new(cmd, updated_paths, no_shell).map_err(|e| e.into())
|
||||
pub fn spawn(cmd: &[String], updated_paths: &[PathOp], no_shell: bool, no_environment: bool) -> Result<Process> {
|
||||
self::imp::Process::new(cmd, updated_paths, no_shell, no_environment).map_err(|e| e.into())
|
||||
}
|
||||
|
||||
pub use self::imp::Process;
|
||||
|
@ -83,7 +83,7 @@ mod imp {
|
|||
|
||||
#[allow(clippy::mutex_atomic)]
|
||||
impl Process {
|
||||
pub fn new(cmd: &[String], updated_paths: &[PathOp], no_shell: bool) -> Result<Self> {
|
||||
pub fn new(cmd: &[String], updated_paths: &[PathOp], no_shell: bool, no_environment: bool) -> Result<Self> {
|
||||
use nix::unistd::*;
|
||||
use std::convert::TryInto;
|
||||
use std::os::unix::process::CommandExt;
|
||||
|
@ -107,7 +107,12 @@ mod imp {
|
|||
|
||||
debug!("Assembled command {:?}", command);
|
||||
|
||||
let command_envs = super::collect_path_env_vars(updated_paths);
|
||||
let command_envs = if no_environment {
|
||||
Vec::new()
|
||||
} else {
|
||||
super::collect_path_env_vars(updated_paths)
|
||||
};
|
||||
|
||||
for &(ref name, ref val) in &command_envs {
|
||||
command.env(name, val);
|
||||
}
|
||||
|
@ -229,7 +234,7 @@ mod imp {
|
|||
}
|
||||
|
||||
impl Process {
|
||||
pub fn new(cmd: &[String], updated_paths: &[PathOp], no_shell: bool) -> Result<Self> {
|
||||
pub fn new(cmd: &[String], updated_paths: &[PathOp], no_shell: bool, no_environment: bool) -> Result<Self> {
|
||||
use std::convert::TryInto;
|
||||
use std::os::windows::io::IntoRawHandle;
|
||||
use std::os::windows::process::CommandExt;
|
||||
|
@ -304,7 +309,12 @@ mod imp {
|
|||
command.creation_flags(CREATE_SUSPENDED);
|
||||
debug!("Assembled command {:?}", command);
|
||||
|
||||
let command_envs = super::collect_path_env_vars(updated_paths);
|
||||
let command_envs = if no_environment {
|
||||
Vec::new()
|
||||
} else {
|
||||
super::collect_path_env_vars(updated_paths)
|
||||
};
|
||||
|
||||
for &(ref name, ref val) in &command_envs {
|
||||
command.env(name, val);
|
||||
}
|
||||
|
|
|
@ -185,7 +185,7 @@ impl ExecHandler {
|
|||
|
||||
debug!("Launching child process");
|
||||
let mut guard = self.child_process.write()?;
|
||||
*guard = Some(process::spawn(&self.args.cmd, ops, self.args.no_shell)?);
|
||||
*guard = Some(process::spawn(&self.args.cmd, ops, self.args.no_shell, self.args.no_environment)?);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue