Add command and shell options to action

This commit is contained in:
Félix Saparelli 2021-08-22 22:06:31 +12:00
parent 613fe24c64
commit 227c2a0e0d
No known key found for this signature in database
GPG key ID: B948C4BAE44FC474
2 changed files with 20 additions and 1 deletions

View file

@ -16,6 +16,7 @@ use tokio::{
use tracing::{debug, trace};
use crate::{
command::Shell,
error::{CriticalError, RuntimeError},
event::Event,
handler::{rte, Handler},
@ -26,8 +27,12 @@ use crate::{
pub struct WorkingData {
pub throttle: Duration,
/// TODO: notes on how outcome is read immediately after handler returns
pub action_handler: Arc<AtomicTake<Box<dyn Handler<Action> + Send>>>,
pub shell: Shell,
/// TODO: notes for command construction ref Shell and old src
pub command: Vec<String>,
}
impl fmt::Debug for WorkingData {
@ -44,6 +49,8 @@ impl Default for WorkingData {
// set to 50ms here, but will remain 100ms on cli until 2022
throttle: Duration::from_millis(50),
action_handler: Arc::new(AtomicTake::new(Box::new(()) as _)),
shell: Shell::default(),
command: Vec::new(),
}
}
}

View file

@ -53,6 +53,18 @@ impl RuntimeConfig {
self
}
/// Set the shell to use to invoke commands.
pub fn command_shell(&mut self, shell: Shell) -> &mut Self {
self.action.shell = shell;
self
}
/// Set the command to run on action.
pub fn command<'cmd>(&mut self, command: impl IntoIterator<Item = &'cmd str>) -> &mut Self {
self.action.command = command.into_iter().map(|c| c.to_owned()).collect();
self
}
/// Set the action handler.
///
/// TODO: notes on how outcome is read immediately after handler returns