summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2022-01-09 23:26:02 -0500
committerJesse Luehrs <doy@tozt.net>2022-01-09 23:26:02 -0500
commitd67d7cda39f5c3a84ee030778d69cdf08634a33c (patch)
tree8f99f1e559201ee8bb70787b13d514c7ba15c13c
parentcba518546d09e9a716c9230ace1bbadd1c14fc2d (diff)
downloadnbsh-d67d7cda39f5c3a84ee030778d69cdf08634a33c.tar.gz
nbsh-d67d7cda39f5c3a84ee030778d69cdf08634a33c.zip
fix builtins wrapping builtins
-rw-r--r--src/runner/builtins/command.rs29
-rw-r--r--src/runner/builtins/mod.rs6
-rw-r--r--src/runner/command.rs29
-rw-r--r--src/runner/mod.rs2
4 files changed, 14 insertions, 52 deletions
diff --git a/src/runner/builtins/command.rs b/src/runner/builtins/command.rs
index 2c1f755..7d84c8f 100644
--- a/src/runner/builtins/command.rs
+++ b/src/runner/builtins/command.rs
@@ -9,23 +9,7 @@ pub struct Command {
}
impl Command {
- pub fn new(exe: crate::parse::Exe) -> Result<Self, crate::parse::Exe> {
- if let Some(s) = exe.exe().to_str() {
- if let Some(f) = super::BUILTINS.get(s) {
- Ok(Self {
- exe,
- f,
- cfg: Cfg::new(),
- })
- } else {
- Err(exe)
- }
- } else {
- Err(exe)
- }
- }
-
- pub fn new_with_io(
+ pub fn new(
exe: crate::parse::Exe,
io: Io,
) -> Result<Self, crate::parse::Exe> {
@@ -34,7 +18,7 @@ impl Command {
Ok(Self {
exe,
f,
- cfg: Cfg::new_with_io(io),
+ cfg: Cfg::new(io),
})
} else {
Err(exe)
@@ -83,14 +67,7 @@ pub struct Cfg {
}
impl Cfg {
- fn new() -> Self {
- Self {
- io: Io::new(),
- pre_exec: None,
- }
- }
-
- fn new_with_io(io: Io) -> Self {
+ fn new(io: Io) -> Self {
Self { io, pre_exec: None }
}
diff --git a/src/runner/builtins/mod.rs b/src/runner/builtins/mod.rs
index 3ae02ea..07be59f 100644
--- a/src/runner/builtins/mod.rs
+++ b/src/runner/builtins/mod.rs
@@ -263,7 +263,7 @@ fn and(
) -> anyhow::Result<command::Child> {
exe.shift();
if env.latest_status().success() {
- let mut cmd = crate::runner::Command::new(exe);
+ let mut cmd = crate::runner::Command::new(exe, cfg.io().clone());
cfg.setup_command(&mut cmd);
Ok(command::Child::new_wrapped(cmd.spawn(env)?))
} else {
@@ -282,7 +282,7 @@ fn or(
let status = *env.latest_status();
Ok(command::Child::new_fut(async move { status }))
} else {
- let mut cmd = crate::runner::Command::new(exe);
+ let mut cmd = crate::runner::Command::new(exe, cfg.io().clone());
cfg.setup_command(&mut cmd);
Ok(command::Child::new_wrapped(cmd.spawn(env)?))
}
@@ -305,7 +305,7 @@ fn builtin(
cfg: command::Cfg,
) -> anyhow::Result<command::Child> {
exe.shift();
- let mut cmd = crate::runner::Command::new_builtin(exe);
+ let mut cmd = crate::runner::Command::new_builtin(exe, cfg.io().clone());
cfg.setup_command(&mut cmd);
Ok(command::Child::new_wrapped(cmd.spawn(env)?))
}
diff --git a/src/runner/command.rs b/src/runner/command.rs
index 34b770e..5d4c11e 100644
--- a/src/runner/command.rs
+++ b/src/runner/command.rs
@@ -9,11 +9,11 @@ pub struct Command {
>,
}
impl Command {
- pub fn new(exe: crate::parse::Exe) -> Self {
+ pub fn new(exe: crate::parse::Exe, io: super::builtins::Io) -> Self {
let exe_path = exe.exe().to_path_buf();
let redirects = exe.redirects().to_vec();
Self {
- inner: super::builtins::Command::new(exe).map_or_else(
+ inner: super::builtins::Command::new(exe, io).map_or_else(
|exe| Self::new_binary(exe).inner,
Inner::Builtin,
),
@@ -23,24 +23,6 @@ impl Command {
}
}
- pub fn new_with_io(
- exe: crate::parse::Exe,
- io: super::builtins::Io,
- ) -> Self {
- let exe_path = exe.exe().to_path_buf();
- let redirects = exe.redirects().to_vec();
- Self {
- inner: super::builtins::Command::new_with_io(exe, io)
- .map_or_else(
- |exe| Self::new_binary(exe).inner,
- Inner::Builtin,
- ),
- exe: exe_path,
- redirects,
- pre_exec: None,
- }
- }
-
#[allow(clippy::needless_pass_by_value)]
pub fn new_binary(exe: crate::parse::Exe) -> Self {
let exe_path = exe.exe().to_path_buf();
@@ -55,11 +37,14 @@ impl Command {
}
}
- pub fn new_builtin(exe: crate::parse::Exe) -> Self {
+ pub fn new_builtin(
+ exe: crate::parse::Exe,
+ io: super::builtins::Io,
+ ) -> Self {
let exe_path = exe.exe().to_path_buf();
let redirects = exe.redirects().to_vec();
Self {
- inner: super::builtins::Command::new(exe)
+ inner: super::builtins::Command::new(exe, io)
.map_or_else(|_| todo!(), Inner::Builtin),
exe: exe_path,
redirects,
diff --git a/src/runner/mod.rs b/src/runner/mod.rs
index 956afde..22121c2 100644
--- a/src/runner/mod.rs
+++ b/src/runner/mod.rs
@@ -243,7 +243,7 @@ fn spawn_children<'a>(
let pipeline = pipeline.eval(env);
let mut cmds: Vec<_> = pipeline
.into_exes()
- .map(|exe| Command::new_with_io(exe, io.clone()))
+ .map(|exe| Command::new(exe, io.clone()))
.collect();
for i in 0..(cmds.len() - 1) {
let (r, w) = pipe()?;