forked from extern/nushell
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,
|
registry: &CommandRegistry,
|
||||||
) -> Result<OutputStream, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
let registry = registry.clone();
|
let registry = registry.clone();
|
||||||
|
let is_last = raw_args.call_info.args.is_last;
|
||||||
|
|
||||||
let mut context = Context::from_raw(&raw_args, ®istry);
|
let mut context = Context::from_raw(&raw_args, ®istry);
|
||||||
let scope = raw_args.call_info.scope.clone();
|
let scope = raw_args.call_info.scope.clone();
|
||||||
let (
|
let (
|
||||||
DoArgs {
|
DoArgs {
|
||||||
ignore_errors,
|
ignore_errors,
|
||||||
block,
|
mut block,
|
||||||
},
|
},
|
||||||
input,
|
input,
|
||||||
) = raw_args.process(®istry).await?;
|
) = raw_args.process(®istry).await?;
|
||||||
|
block.set_is_last(!is_last);
|
||||||
|
|
||||||
let result = run_block(
|
let result = run_block(
|
||||||
&block,
|
&block,
|
||||||
|
@ -40,7 +40,9 @@ impl WholeStreamCommand for AliasCommand {
|
|||||||
) -> Result<OutputStream, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
let call_info = args.call_info.clone();
|
let call_info = args.call_info.clone();
|
||||||
let registry = registry.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 alias_command = self.clone();
|
||||||
let mut context = Context::from_args(&args, ®istry);
|
let mut context = Context::from_args(&args, ®istry);
|
||||||
let input = args.input;
|
let input = args.input;
|
||||||
|
@ -196,6 +196,9 @@ async fn evaluate_invocation(
|
|||||||
|
|
||||||
let input = InputStream::empty();
|
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 result = run_block(&block, &mut context, input, it, vars, env).await?;
|
||||||
|
|
||||||
let output = result.into_vec().await;
|
let output = result.into_vec().await;
|
||||||
|
@ -200,6 +200,28 @@ impl Block {
|
|||||||
commands.expand_it_usage();
|
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)]
|
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Clone, Hash, Deserialize, Serialize)]
|
||||||
|
@ -84,13 +84,25 @@ fn it_expansion_of_invocation() {
|
|||||||
assert_eq!(actual.out, "4");
|
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]
|
#[test]
|
||||||
fn argument_invocation() {
|
fn argument_invocation() {
|
||||||
let actual = nu!(
|
let actual = nu!(
|
||||||
cwd: ".",
|
cwd: ".",
|
||||||
r#"
|
r#"
|
||||||
echo "foo" | echo $(echo $it)
|
echo "foo" | echo $(echo $it)
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(actual.out, "foo");
|
assert_eq!(actual.out, "foo");
|
||||||
|
Loading…
Reference in New Issue
Block a user