pub struct Launcher {
pub prefix: Vec<OsString>,
pub cwd: Option<PathBuf>,
pub env: Vec<(OsString, OsString)>,
pub unset_env: Vec<OsString>,
}Expand description
How tools start processes: under a wrapper program (a sandbox such as
bwrap … --, nice -n 10, a container’s exec), in a directory, with
variables set and removed. Every command it builds is detached. A
host that hands one launcher to every tool that starts processes
(Shell, a background job, a formatter) puts them all
under the same policy.
use rig_tools::process::Launcher;
let launcher = Launcher::default()
.wrapped(["nice", "-n", "10"])
.in_dir("/srv/project")
.with_env("CI", "1")
.without_env(["AGENT_TOKEN"]);
let mut command = launcher.command("sh");
command.args(["-c", "make test"]);
assert_eq!(command.get_program(), "nice");
let args: Vec<_> = command.get_args().collect();
assert_eq!(args, ["-n", "10", "sh", "-c", "make test"]);
assert_eq!(command.get_current_dir(), Some(std::path::Path::new("/srv/project")));Fields§
§prefix: Vec<OsString>The program and arguments every command runs under; empty runs the command itself.
cwd: Option<PathBuf>The directory commands start in; None is this process’s.
env: Vec<(OsString, OsString)>Variables set for every command.
unset_env: Vec<OsString>Variables no command inherits, such as those that make a program act as the agent that runs it.
Implementations§
Source§impl Launcher
impl Launcher
Sourcepub fn wrapped(
self,
prefix: impl IntoIterator<Item = impl Into<OsString>>,
) -> Self
pub fn wrapped( self, prefix: impl IntoIterator<Item = impl Into<OsString>>, ) -> Self
The same launcher, running every command under prefix.
Sourcepub fn in_dir(self, dir: impl Into<PathBuf>) -> Self
pub fn in_dir(self, dir: impl Into<PathBuf>) -> Self
The same launcher, starting commands in dir.
Sourcepub fn with_env(
self,
name: impl Into<OsString>,
value: impl Into<OsString>,
) -> Self
pub fn with_env( self, name: impl Into<OsString>, value: impl Into<OsString>, ) -> Self
The same launcher, setting name to value for every command.
Sourcepub fn without_env(
self,
names: impl IntoIterator<Item = impl Into<OsString>>,
) -> Self
pub fn without_env( self, names: impl IntoIterator<Item = impl Into<OsString>>, ) -> Self
The same launcher, keeping names from every command.
Sourcepub fn command(&self, program: impl AsRef<OsStr>) -> Command
pub fn command(&self, program: impl AsRef<OsStr>) -> Command
A detached command that runs program under this launcher’s policy;
add the program’s arguments to it.
Sourcepub fn spawn(
&self,
program: impl AsRef<OsStr>,
args: impl IntoIterator<Item = impl AsRef<OsStr>>,
how: Spawn,
) -> Result<Process>
pub fn spawn( &self, program: impl AsRef<OsStr>, args: impl IntoIterator<Item = impl AsRef<OsStr>>, how: Spawn, ) -> Result<Process>
Starts program with args under this launcher’s policy, as
command builds it, with stdin and output as how
says.
use rig_tools::process::{Launcher, OutputLine, Spawn};
let how = Spawn { stdin: Some(b"hello\n".to_vec()), ..Spawn::default() };
let mut process = Launcher::default().spawn("cat", ["-"], how)?;
let status = process.wait_for(std::time::Duration::from_secs(5))?;
assert!(status.is_some_and(|status| status.success()));
let lines: Vec<OutputLine> = process.lines().iter().collect();
assert_eq!(lines, [OutputLine::Out("hello\n".to_owned())]);Trait Implementations§
impl Eq for Launcher
impl StructuralPartialEq for Launcher
Auto Trait Implementations§
impl Freeze for Launcher
impl RefUnwindSafe for Launcher
impl Send for Launcher
impl Sync for Launcher
impl Unpin for Launcher
impl UnsafeUnpin for Launcher
impl UnwindSafe for Launcher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.