mirror of
https://github.com/watchexec/watchexec.git
synced 2024-09-29 22:51:33 +02:00
Add environment vars support
This commit is contained in:
parent
53d9a65e5f
commit
9ed3645088
@ -135,9 +135,9 @@ pub fn get_args(tagged_filterer: bool) -> Result<ArgMatches<'static>> {
|
|||||||
.help("Do not wrap command in a shell. Deprecated: use --shell=none instead.")
|
.help("Do not wrap command in a shell. Deprecated: use --shell=none instead.")
|
||||||
.short("n")
|
.short("n")
|
||||||
.long("no-shell"))
|
.long("no-shell"))
|
||||||
.arg(Arg::with_name("no-environment") // TODO
|
.arg(Arg::with_name("no-environment")
|
||||||
.help_heading(Some(OPTSET_OUTPUT))
|
.help_heading(Some(OPTSET_OUTPUT))
|
||||||
.help("Do not set WATCHEXEC_*_PATH environment variables for the command")
|
.help("Do not set WATCHEXEC_* environment variables for the command")
|
||||||
.long("no-environment"))
|
.long("no-environment"))
|
||||||
.arg(Arg::with_name("no-process-group")
|
.arg(Arg::with_name("no-process-group")
|
||||||
.help_heading(Some(OPTSET_COMMAND))
|
.help_heading(Some(OPTSET_COMMAND))
|
||||||
@ -201,7 +201,7 @@ pub fn get_args(tagged_filterer: bool) -> Result<ArgMatches<'static>> {
|
|||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("filter") // TODO
|
Arg::with_name("filter")
|
||||||
.help_heading(Some(OPTSET_FILTERING))
|
.help_heading(Some(OPTSET_FILTERING))
|
||||||
.help("Ignore all modifications except those matching the pattern")
|
.help("Ignore all modifications except those matching the pattern")
|
||||||
.short("f")
|
.short("f")
|
||||||
@ -212,7 +212,7 @@ pub fn get_args(tagged_filterer: bool) -> Result<ArgMatches<'static>> {
|
|||||||
.value_name("pattern"),
|
.value_name("pattern"),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("ignore") // TODO
|
Arg::with_name("ignore")
|
||||||
.help_heading(Some(OPTSET_FILTERING))
|
.help_heading(Some(OPTSET_FILTERING))
|
||||||
.help("Ignore modifications to paths matching the pattern")
|
.help("Ignore modifications to paths matching the pattern")
|
||||||
.short("i")
|
.short("i")
|
||||||
|
@ -4,11 +4,13 @@ use clap::ArgMatches;
|
|||||||
use miette::{IntoDiagnostic, Result};
|
use miette::{IntoDiagnostic, Result};
|
||||||
use notify_rust::Notification;
|
use notify_rust::Notification;
|
||||||
use watchexec::{
|
use watchexec::{
|
||||||
action::{Action, Outcome},
|
action::{Action, Outcome, PostSpawn, PreSpawn},
|
||||||
command::Shell,
|
command::Shell,
|
||||||
config::RuntimeConfig,
|
config::RuntimeConfig,
|
||||||
event::ProcessEnd,
|
event::ProcessEnd,
|
||||||
fs::Watcher,
|
fs::Watcher,
|
||||||
|
handler::SyncFnHandler,
|
||||||
|
paths::summarise_events_to_env,
|
||||||
signal::{process::SubSignal, source::MainSignal},
|
signal::{process::SubSignal, source::MainSignal},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -194,7 +196,34 @@ pub fn runtime(args: &ArgMatches<'static>) -> Result<RuntimeConfig> {
|
|||||||
fut
|
fut
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: pre-command (environment vars)
|
let no_env = args.is_present("no-environment");
|
||||||
|
config.on_pre_spawn(move |prespawn: PreSpawn| async move {
|
||||||
|
if !no_env {
|
||||||
|
let envs = summarise_events_to_env(prespawn.events.iter());
|
||||||
|
if let Some(mut command) = prespawn.command().await {
|
||||||
|
for (k, v) in envs {
|
||||||
|
command.env(format!("WATCHEXEC_{}", k), v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok::<(), Infallible>(())
|
||||||
|
});
|
||||||
|
|
||||||
|
config.on_post_spawn(SyncFnHandler::from(move |postspawn: PostSpawn| {
|
||||||
|
if notif {
|
||||||
|
Notification::new()
|
||||||
|
.summary("Watchexec: change detected")
|
||||||
|
.body(&format!("Running `{}`", postspawn.command.join(" ")))
|
||||||
|
.show()
|
||||||
|
.map(drop)
|
||||||
|
.unwrap_or_else(|err| {
|
||||||
|
eprintln!("Failed to send desktop notification: {}", err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok::<(), Infallible>(())
|
||||||
|
}));
|
||||||
|
|
||||||
Ok(config)
|
Ok(config)
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ FLAGS:
|
|||||||
-c, --clear Clear screen before executing command
|
-c, --clear Clear screen before executing command
|
||||||
-h, --help Prints help information
|
-h, --help Prints help information
|
||||||
--no-default-ignore Skip auto-ignoring of commonly ignored globs
|
--no-default-ignore Skip auto-ignoring of commonly ignored globs
|
||||||
--no-environment Do not set WATCHEXEC_*_PATH environment variables for the command
|
--no-environment Do not set WATCHEXEC_* environment variables for the command
|
||||||
--no-global-ignore Skip auto-loading of global or environment-wide ignore files
|
--no-global-ignore Skip auto-loading of global or environment-wide ignore files
|
||||||
--no-meta Ignore metadata changes
|
--no-meta Ignore metadata changes
|
||||||
--no-process-group Do not use a process group when running the command
|
--no-process-group Do not use a process group when running the command
|
||||||
|
@ -13,7 +13,7 @@ FLAGS:
|
|||||||
-c, --clear Clear screen before executing command
|
-c, --clear Clear screen before executing command
|
||||||
-h, --help Prints help information
|
-h, --help Prints help information
|
||||||
--no-default-ignore Skip auto-ignoring of commonly ignored globs
|
--no-default-ignore Skip auto-ignoring of commonly ignored globs
|
||||||
--no-environment Do not set WATCHEXEC_*_PATH environment variables for the command
|
--no-environment Do not set WATCHEXEC_* environment variables for the command
|
||||||
--no-global-ignore Skip auto-loading of global or environment-wide ignore files
|
--no-global-ignore Skip auto-loading of global or environment-wide ignore files
|
||||||
--no-meta Ignore metadata changes
|
--no-meta Ignore metadata changes
|
||||||
--no-process-group Do not use a process group when running the command
|
--no-process-group Do not use a process group when running the command
|
||||||
|
Loading…
Reference in New Issue
Block a user