mirror of
https://github.com/watchexec/watchexec.git
synced 2024-11-13 07:41:11 +01:00
Implement Outcome::Wait, and CLI on-busy=queue
This commit is contained in:
parent
b923638cbd
commit
645ab74c62
2 changed files with 30 additions and 23 deletions
|
@ -100,8 +100,7 @@ fn runtime(args: &ArgMatches<'static>) -> Result<RuntimeConfig> {
|
|||
}
|
||||
|
||||
if once {
|
||||
// TODO
|
||||
// action.outcome(Outcome::both(Outcome::Start, Outcome::both(Outcome::Wait, Outcome::Exit));
|
||||
action.outcome(Outcome::both(Outcome::Start, Outcome::wait(Outcome::Exit)));
|
||||
return fut;
|
||||
}
|
||||
|
||||
|
@ -125,23 +124,23 @@ fn runtime(args: &ArgMatches<'static>) -> Result<RuntimeConfig> {
|
|||
|
||||
if !has_paths {
|
||||
if !signals.is_empty() {
|
||||
let mut out = Outcome::DoNothing;
|
||||
for sig in signals {
|
||||
out = Outcome::both(
|
||||
out,
|
||||
Outcome::Signal(match sig {
|
||||
InputSignal::Hangup => Signal::SIGHUP,
|
||||
InputSignal::Interrupt => Signal::SIGINT,
|
||||
InputSignal::Quit => Signal::SIGQUIT,
|
||||
InputSignal::Terminate => Signal::SIGTERM,
|
||||
InputSignal::User1 => Signal::SIGUSR1,
|
||||
InputSignal::User2 => Signal::SIGUSR2,
|
||||
}),
|
||||
);
|
||||
}
|
||||
let mut out = Outcome::DoNothing;
|
||||
for sig in signals {
|
||||
out = Outcome::both(
|
||||
out,
|
||||
Outcome::Signal(match sig {
|
||||
InputSignal::Hangup => Signal::SIGHUP,
|
||||
InputSignal::Interrupt => Signal::SIGINT,
|
||||
InputSignal::Quit => Signal::SIGQUIT,
|
||||
InputSignal::Terminate => Signal::SIGTERM,
|
||||
InputSignal::User1 => Signal::SIGUSR1,
|
||||
InputSignal::User2 => Signal::SIGUSR2,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
action.outcome(out);
|
||||
return fut;
|
||||
action.outcome(out);
|
||||
return fut;
|
||||
}
|
||||
|
||||
let completion = action.events.iter().flat_map(|e| e.completions()).next();
|
||||
|
@ -165,8 +164,8 @@ fn runtime(args: &ArgMatches<'static>) -> Result<RuntimeConfig> {
|
|||
}
|
||||
(false, "restart") => Outcome::both(Outcome::Stop, Outcome::Start),
|
||||
(_, "signal") => Outcome::Signal(signal),
|
||||
// (true, "queue") => Outcome::wait(Outcome::both(Outcome::Clear, Outcome::Start)),
|
||||
// (false, "queue") => Outcome::wait(Outcome::Start),
|
||||
(true, "queue") => Outcome::wait(Outcome::both(Outcome::Clear, Outcome::Start)),
|
||||
(false, "queue") => Outcome::wait(Outcome::Start),
|
||||
_ => Outcome::DoNothing,
|
||||
};
|
||||
|
||||
|
|
|
@ -148,9 +148,9 @@ pub enum Outcome {
|
|||
/// If the command isn't running, start it.
|
||||
Start,
|
||||
|
||||
// TODO
|
||||
// /// Wait for command completion, then start a new one.
|
||||
// Queue,
|
||||
/// Wait for command completion.
|
||||
Wait,
|
||||
|
||||
/// Send this signal to the command.
|
||||
Signal(Signal),
|
||||
|
||||
|
@ -182,6 +182,10 @@ impl Outcome {
|
|||
Self::Both(Box::new(one), Box::new(two))
|
||||
}
|
||||
|
||||
pub fn wait(and_then: Outcome) -> Self {
|
||||
Self::Both(Box::new(Outcome::Wait), Box::new(and_then))
|
||||
}
|
||||
|
||||
fn resolve(self, is_running: bool) -> Self {
|
||||
match (is_running, self) {
|
||||
(true, Self::IfRunning(then, _)) => then.resolve(true),
|
||||
|
@ -379,6 +383,10 @@ async fn apply_outcome(
|
|||
p.signal(sig).await;
|
||||
}
|
||||
|
||||
(Some(p), Outcome::Wait) => {
|
||||
p.wait().await?;
|
||||
}
|
||||
|
||||
(_, Outcome::Clear) => {
|
||||
clearscreen::clear()?;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue