From 227c2a0e0df4e7aafc54bd5849175ddd9298b6c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Saparelli?= Date: Sun, 22 Aug 2021 22:06:31 +1200 Subject: [PATCH] Add command and shell options to action --- lib/src/action.rs | 9 ++++++++- lib/src/config.rs | 12 ++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/src/action.rs b/lib/src/action.rs index d65b0b11..6bc72058 100644 --- a/lib/src/action.rs +++ b/lib/src/action.rs @@ -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 + Send>>>, + + pub shell: Shell, + + /// TODO: notes for command construction ref Shell and old src + pub command: Vec, } 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(), } } } diff --git a/lib/src/config.rs b/lib/src/config.rs index a8e4215d..c17f82f4 100644 --- a/lib/src/config.rs +++ b/lib/src/config.rs @@ -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) -> &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