Skip to content

Commit 085cdbc

Browse files
committed
Fixed bug with default shell - now takes args
1 parent 8a3e180 commit 085cdbc

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

core/src/command/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use self::providers::NixRemoteProvider;
1818

1919
#[derive(Serialize, Deserialize)]
2020
pub struct Command {
21-
shell: String,
22-
cmd: String,
21+
shell: Vec<String>,
22+
cmd: Vec<String>,
2323
}
2424

2525
#[derive(Debug, Serialize, Deserialize)]
@@ -32,7 +32,7 @@ pub struct CommandResult {
3232

3333
pub trait CommandProvider<'a> {
3434
fn available(&Host) -> bool where Self: Sized;
35-
fn try_new<S: Into<String>>(&'a Host, S, Option<&str>) -> Option<Self> where Self: Sized;
35+
fn try_new(&'a Host, &[&str], Option<&[&str]>) -> Option<Self> where Self: Sized;
3636
fn exec(&self) -> Result<CommandResult>;
3737
}
3838

@@ -49,7 +49,7 @@ impl <'de>ExecutableProvider<'de> for RemoteProvider {
4949
}
5050
}
5151

52-
pub fn factory<'a, S: Into<String>>(host: &'a Host, cmd: S, shell: Option<&str>) -> Result<Box<CommandProvider<'a> + 'a>> {
52+
pub fn factory<'a>(host: &'a Host, cmd: &[&str], shell: Option<&[&str]>) -> Result<Box<CommandProvider<'a> + 'a>> {
5353
if let Some(p) = Nix::try_new(host, cmd, shell) {
5454
Ok(Box::new(p))
5555
} else {

core/src/command/providers/nix.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ use ExecutableProvider;
1111
use host::*;
1212
use std::process;
1313

14+
const DEFAULT_SHELL: [&'static str; 2] = ["/bin/sh", "-c"];
15+
1416
pub struct Nix<'a> {
1517
host: &'a Host,
1618
inner: Command
@@ -46,11 +48,11 @@ impl <'a>CommandProvider<'a> for Nix<'a> {
4648
}
4749
}
4850

49-
fn try_new<S: Into<String>>(host: &'a Host, cmd: S, shell: Option<&str>) -> Option<Nix<'a>> {
51+
fn try_new(host: &'a Host, cmd: &[&str], shell: Option<&[&str]>) -> Option<Nix<'a>> {
5052
if Self::available(host) {
5153
let inner = Command {
52-
shell: shell.unwrap_or("/bin/sh").into(),
53-
cmd: cmd.into(),
54+
shell: shell.unwrap_or(&DEFAULT_SHELL).to_owned().iter().map(|s| s.to_string()).collect(),
55+
cmd: cmd.to_owned().iter().map(|s| s.to_string()).collect(),
5456
};
5557
Some(Nix { host, inner })
5658
} else {
@@ -60,8 +62,11 @@ impl <'a>CommandProvider<'a> for Nix<'a> {
6062

6163
fn exec(&self) -> Result<CommandResult> {
6264
if self.host.is_local() {
63-
let out = process::Command::new(&self.inner.shell)
64-
.arg(&self.inner.cmd)
65+
let (shell, shell_args) = self.inner.shell.split_first()
66+
.ok_or("Invalid shell provided")?;
67+
let out = process::Command::new(shell)
68+
.args(shell_args)
69+
.args(&self.inner.cmd)
6570
.output()
6671
.chain_err(|| "Command execution failed")?;
6772
Ok(CommandResult {

0 commit comments

Comments
 (0)