mirror of
https://github.com/nushell/nushell.git
synced 2024-11-22 08:23:24 +01:00
Properly redirect invocations (#2070)
* Properly redirect invocations * Don't convert with-env yet, as there's a random test failure
This commit is contained in:
parent
8b3964f518
commit
dffc9c9b1c
@ -61,16 +61,18 @@ async fn do_(
|
||||
registry: &CommandRegistry,
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
let registry = registry.clone();
|
||||
let is_last = raw_args.call_info.args.is_last;
|
||||
|
||||
let mut context = Context::from_raw(&raw_args, ®istry);
|
||||
let scope = raw_args.call_info.scope.clone();
|
||||
let (
|
||||
DoArgs {
|
||||
ignore_errors,
|
||||
block,
|
||||
mut block,
|
||||
},
|
||||
input,
|
||||
) = raw_args.process(®istry).await?;
|
||||
block.set_is_last(!is_last);
|
||||
|
||||
let result = run_block(
|
||||
&block,
|
||||
|
@ -40,7 +40,9 @@ impl WholeStreamCommand for AliasCommand {
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
let call_info = args.call_info.clone();
|
||||
let registry = registry.clone();
|
||||
let block = self.block.clone();
|
||||
let mut block = self.block.clone();
|
||||
block.set_is_last(!call_info.args.is_last);
|
||||
|
||||
let alias_command = self.clone();
|
||||
let mut context = Context::from_args(&args, ®istry);
|
||||
let input = args.input;
|
||||
|
@ -196,6 +196,9 @@ async fn evaluate_invocation(
|
||||
|
||||
let input = InputStream::empty();
|
||||
|
||||
let mut block = block.clone();
|
||||
block.set_is_last(true);
|
||||
|
||||
let result = run_block(&block, &mut context, input, it, vars, env).await?;
|
||||
|
||||
let output = result.into_vec().await;
|
||||
|
@ -200,6 +200,28 @@ impl Block {
|
||||
commands.expand_it_usage();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_is_last(&mut self, is_last: bool) {
|
||||
if let Some(pipeline) = self.block.last_mut() {
|
||||
if let Some(command) = pipeline.list.last_mut() {
|
||||
if let ClassifiedCommand::Internal(internal) = command {
|
||||
internal.args.is_last = is_last;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_is_last(&mut self) -> Option<bool> {
|
||||
if let Some(pipeline) = self.block.last_mut() {
|
||||
if let Some(command) = pipeline.list.last_mut() {
|
||||
if let ClassifiedCommand::Internal(internal) = command {
|
||||
return Some(internal.args.is_last);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Clone, Hash, Deserialize, Serialize)]
|
||||
|
@ -84,13 +84,25 @@ fn it_expansion_of_invocation() {
|
||||
assert_eq!(actual.out, "4");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invocation_properly_redirects() {
|
||||
let actual = nu!(
|
||||
cwd: ".",
|
||||
r#"
|
||||
echo $(nu --testbin cococo "hello") | str collect
|
||||
"#
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "hello");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn argument_invocation() {
|
||||
let actual = nu!(
|
||||
cwd: ".",
|
||||
r#"
|
||||
echo "foo" | echo $(echo $it)
|
||||
"#
|
||||
echo "foo" | echo $(echo $it)
|
||||
"#
|
||||
);
|
||||
|
||||
assert_eq!(actual.out, "foo");
|
||||
|
Loading…
Reference in New Issue
Block a user