1//! A module for working with processes.
2
3use crate::wit::zed::extension::process;
4pub use crate::wit::zed::extension::process::{Command, Output};
5
6impl Command {
7 pub fn new(program: impl Into<String>) -> Self {
8 Self {
9 command: program.into(),
10 args: Vec::new(),
11 env: Vec::new(),
12 }
13 }
14
15 pub fn arg(mut self, arg: impl Into<String>) -> Self {
16 self.args.push(arg.into());
17 self
18 }
19
20 pub fn args(mut self, args: impl IntoIterator<Item = impl Into<String>>) -> Self {
21 self.args.extend(args.into_iter().map(Into::into));
22 self
23 }
24
25 pub fn env(mut self, key: impl Into<String>, value: impl Into<String>) -> Self {
26 self.env.push((key.into(), value.into()));
27 self
28 }
29
30 pub fn envs(
31 mut self,
32 envs: impl IntoIterator<Item = (impl Into<String>, impl Into<String>)>,
33 ) -> Self {
34 self.env.extend(
35 envs.into_iter()
36 .map(|(key, value)| (key.into(), value.into())),
37 );
38 self
39 }
40
41 pub fn output(&mut self) -> Result<Output, String> {
42 process::run_command(self)
43 }
44}