Skip to content

Commit

Permalink
Merge pull request #87 from matheuswhite/85-quiet-exec
Browse files Browse the repository at this point in the history
Add quiet optional argument to `scope.exec`
  • Loading branch information
matheuswhite authored May 9, 2024
2 parents 1c573ef + f0a043a commit cec8f0c
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
5 changes: 3 additions & 2 deletions plugins/scope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ scope = {
sleep = function(time)
coroutine.yield({ ":sleep", time })
end,
exec = function(cmd)
local _, stdout, stderr = coroutine.yield({ ":exec", cmd })
exec = function(cmd, quiet)
quiet = quiet or false
local _, stdout, stderr = coroutine.yield({ ":exec", cmd, quiet })
return stdout, stderr
end
}
2 changes: 2 additions & 0 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub enum PluginRequest {
},
Exec {
cmd: String,
quiet: bool,
},
}

Expand Down Expand Up @@ -150,6 +151,7 @@ impl<'a> TryFrom<Table<'a>> for PluginRequest {
}
":exec" => Ok(PluginRequest::Exec {
cmd: value.get(2).map_err(|err| err.to_string())?,
quiet: value.get(3).map_err(|err| err.to_string())?,
}),
_ => Err("Unknown function".to_string()),
}
Expand Down
4 changes: 2 additions & 2 deletions src/plugin_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ impl PluginManager {
}
}
PluginRequest::Sleep { time } => tokio::time::sleep(time).await,
PluginRequest::Exec { cmd } => match origin {
PluginRequest::Exec { cmd, quiet } => match origin {
ExecutionOrigin::SerialRx => {
Plugin::eprintln(
text_view,
Expand All @@ -313,7 +313,7 @@ impl PluginManager {
flags.has_process_running.store(true, Ordering::SeqCst);
let res = Some(
process_runner
.run(plugin_name, cmd, flags.stop_process.clone())
.run(plugin_name, cmd, quiet, flags.stop_process.clone())
.await
.unwrap(),
);
Expand Down
13 changes: 10 additions & 3 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ impl ProcessRunner {
&self,
plugin_name: String,
cmd: String,
quiet: bool,
stop_process_flag: Arc<AtomicBool>,
) -> Result<PluginRequestResult, String> {
Plugin::println(self.text_view.clone(), plugin_name.clone(), cmd.clone()).await;
if !quiet {
Plugin::println(self.text_view.clone(), plugin_name.clone(), cmd.clone()).await;
}

let mut child = if cfg!(target_os = "windows") {
Command::new("cmd")
Expand Down Expand Up @@ -67,7 +70,9 @@ impl ProcessRunner {
}

buffer.push(line.clone());
Plugin::println(text_view2.clone(), plugin_name.clone(), line.clone()).await;
if !quiet {
Plugin::println(text_view2.clone(), plugin_name.clone(), line.clone()).await;
}
}

buffer
Expand All @@ -84,7 +89,9 @@ impl ProcessRunner {
}

buffer.push(line.clone());
Plugin::eprintln(text_view3.clone(), plugin_name2.clone(), line).await;
if !quiet {
Plugin::eprintln(text_view3.clone(), plugin_name2.clone(), line).await;
}
}

buffer
Expand Down

0 comments on commit cec8f0c

Please sign in to comment.