mirror of
https://github.com/nushell/nushell
synced 2024-12-26 13:03:07 +00:00
Internal to external (#51)
Add a simple form of internal->external support
This commit is contained in:
parent
ffe2896aac
commit
5043367d11
2 changed files with 30 additions and 18 deletions
13
src/cli.rs
13
src/cli.rs
|
@ -212,14 +212,11 @@ async fn process_line(readline: Result<String, ReadlineError>, ctx: &mut Context
|
|||
},
|
||||
|
||||
(
|
||||
Some(ClassifiedCommand::Internal(ref i)),
|
||||
Some(ClassifiedCommand::External(ref e)),
|
||||
) => {
|
||||
return LineResult::Error(ShellError::string(&format!(
|
||||
"Unimplemented Internal({}) -> External({})",
|
||||
i.name(),
|
||||
e.name()
|
||||
)))
|
||||
Some(ClassifiedCommand::Internal(left)),
|
||||
Some(ClassifiedCommand::External(_)),
|
||||
) => match left.run(ctx, input).await {
|
||||
Ok(val) => ClassifiedInputStream::from_input_stream(val),
|
||||
Err(err) => return LineResult::Error(err),
|
||||
}
|
||||
|
||||
(
|
||||
|
|
|
@ -105,10 +105,6 @@ impl InternalCommand {
|
|||
|
||||
Ok(stream.boxed() as InputStream)
|
||||
}
|
||||
|
||||
crate fn name(&self) -> &str {
|
||||
self.command.name()
|
||||
}
|
||||
}
|
||||
|
||||
crate struct ExternalCommand {
|
||||
|
@ -129,10 +125,33 @@ impl ExternalCommand {
|
|||
input: ClassifiedInputStream,
|
||||
stream_next: StreamNext,
|
||||
) -> Result<ClassifiedInputStream, ShellError> {
|
||||
let inputs: Vec<Value> = input.objects.collect().await;
|
||||
|
||||
let mut arg_string = format!("{}", self.name);
|
||||
for arg in &self.args {
|
||||
arg_string.push_str(" ");
|
||||
arg_string.push_str(&arg);
|
||||
}
|
||||
let mut process = Exec::shell(&self.name);
|
||||
|
||||
for arg in self.args {
|
||||
process = process.arg(arg)
|
||||
if arg_string.contains("$it") {
|
||||
let mut first = true;
|
||||
for i in &inputs {
|
||||
if !first {
|
||||
process = process.arg("&&");
|
||||
process = process.arg(&self.name);
|
||||
} else {
|
||||
first = false;
|
||||
}
|
||||
|
||||
for arg in &self.args {
|
||||
process = process.arg(&arg.replace("$it", &i.as_string().unwrap()));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for arg in &self.args {
|
||||
process = process.arg(arg);
|
||||
}
|
||||
}
|
||||
|
||||
process = process.cwd(context.env.lock().unwrap().cwd());
|
||||
|
@ -168,8 +187,4 @@ impl ExternalCommand {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
crate fn name(&self) -> &str {
|
||||
&self.name[..]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue