forked from extern/nushell
Fix per-item run_alias (#1669)
* Fix per-item run_alias * Fix 1609 also
This commit is contained in:
parent
8bd3cedce1
commit
006171d669
@ -489,10 +489,6 @@ impl Command {
|
|||||||
scope: raw_args.call_info.scope.clone().set_it(x.clone()),
|
scope: raw_args.call_info.scope.clone().set_it(x.clone()),
|
||||||
}
|
}
|
||||||
.evaluate(®istry);
|
.evaluate(®istry);
|
||||||
// let call_info = raw_args
|
|
||||||
// .clone()
|
|
||||||
// .call_info
|
|
||||||
// .evaluate(®istry, &Scope::it_value(x.clone()));
|
|
||||||
|
|
||||||
match call_info {
|
match call_info {
|
||||||
Ok(call_info) => match command.run(&call_info, ®istry, &raw_args, x) {
|
Ok(call_info) => match command.run(&call_info, ®istry, &raw_args, x) {
|
||||||
|
@ -6,7 +6,7 @@ use crate::prelude::*;
|
|||||||
use futures::stream::once;
|
use futures::stream::once;
|
||||||
|
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{hir::Block, ReturnSuccess, Scope, Signature, SyntaxShape};
|
use nu_protocol::{hir::Block, ReturnSuccess, Signature, SyntaxShape};
|
||||||
|
|
||||||
pub struct Each;
|
pub struct Each;
|
||||||
|
|
||||||
@ -47,6 +47,7 @@ fn each(
|
|||||||
raw_args: RawCommandArgs,
|
raw_args: RawCommandArgs,
|
||||||
) -> Result<OutputStream, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
let block = each_args.block;
|
let block = each_args.block;
|
||||||
|
let scope = raw_args.call_info.scope.clone();
|
||||||
let registry = context.registry.clone();
|
let registry = context.registry.clone();
|
||||||
let mut input_stream = context.input;
|
let mut input_stream = context.input;
|
||||||
let stream = async_stream! {
|
let stream = async_stream! {
|
||||||
@ -59,7 +60,7 @@ fn each(
|
|||||||
&block,
|
&block,
|
||||||
&mut context,
|
&mut context,
|
||||||
input_stream,
|
input_stream,
|
||||||
&Scope::new(input_clone),
|
&scope.clone().set_it(input_clone),
|
||||||
).await;
|
).await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
|
@ -4,7 +4,7 @@ use crate::prelude::*;
|
|||||||
|
|
||||||
use derive_new::new;
|
use derive_new::new;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{hir::Block, ReturnSuccess, Scope, Signature, SyntaxShape};
|
use nu_protocol::{hir::Block, ReturnSuccess, Signature, SyntaxShape};
|
||||||
|
|
||||||
#[derive(new, Clone)]
|
#[derive(new, Clone)]
|
||||||
pub struct AliasCommand {
|
pub struct AliasCommand {
|
||||||
@ -43,28 +43,22 @@ impl WholeStreamCommand for AliasCommand {
|
|||||||
let block = self.block.clone();
|
let block = self.block.clone();
|
||||||
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 mut input = args.input;
|
let input = args.input;
|
||||||
|
|
||||||
let stream = async_stream! {
|
let stream = async_stream! {
|
||||||
while let Some(input) = input.next().await {
|
let mut scope = call_info.scope.clone();
|
||||||
let call_info = call_info.clone();
|
let evaluated = call_info.evaluate(®istry)?;
|
||||||
let tag = tag.clone();
|
|
||||||
let evaluated = call_info.evaluate_with_new_it(®istry, &input)?;
|
|
||||||
let mut scope = Scope::it_value(input.clone());
|
|
||||||
if let Some(positional) = &evaluated.args.positional {
|
if let Some(positional) = &evaluated.args.positional {
|
||||||
for (pos, arg) in positional.iter().enumerate() {
|
for (pos, arg) in positional.iter().enumerate() {
|
||||||
scope = scope.set_var(alias_command.args[pos].to_string(), arg.clone());
|
scope = scope.set_var(alias_command.args[pos].to_string(), arg.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let input_clone = Ok(input.clone());
|
|
||||||
let input_stream = futures::stream::once(async { input_clone }).boxed().to_input_stream();
|
|
||||||
|
|
||||||
let result = run_block(
|
let result = run_block(
|
||||||
&block,
|
&block,
|
||||||
&mut context,
|
&mut context,
|
||||||
input_stream,
|
input,
|
||||||
&scope
|
&scope,
|
||||||
).await;
|
).await;
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
@ -83,7 +77,6 @@ impl WholeStreamCommand for AliasCommand {
|
|||||||
|
|
||||||
let errors = context.get_errors();
|
let errors = context.get_errors();
|
||||||
if let Some(x) = errors.first() {
|
if let Some(x) = errors.first() {
|
||||||
//yield Err(error.clone());
|
|
||||||
yield Err(ShellError::labeled_error_with_secondary(
|
yield Err(ShellError::labeled_error_with_secondary(
|
||||||
"Alias failed to run",
|
"Alias failed to run",
|
||||||
"alias failed to run",
|
"alias failed to run",
|
||||||
@ -94,7 +87,6 @@ impl WholeStreamCommand for AliasCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
//yield Err(e);
|
|
||||||
yield Err(ShellError::labeled_error_with_secondary(
|
yield Err(ShellError::labeled_error_with_secondary(
|
||||||
"Alias failed to run",
|
"Alias failed to run",
|
||||||
"alias failed to run",
|
"alias failed to run",
|
||||||
@ -104,7 +96,6 @@ impl WholeStreamCommand for AliasCommand {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(stream.to_output_stream())
|
Ok(stream.to_output_stream())
|
||||||
|
@ -3,7 +3,7 @@ use crate::evaluate::evaluate_baseline_expr;
|
|||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use log::trace;
|
use log::trace;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{hir::ClassifiedCommand, Scope, Signature, SyntaxShape, UntaggedValue, Value};
|
use nu_protocol::{hir::ClassifiedCommand, Signature, SyntaxShape, UntaggedValue, Value};
|
||||||
|
|
||||||
pub struct SkipWhile;
|
pub struct SkipWhile;
|
||||||
|
|
||||||
@ -32,6 +32,7 @@ impl WholeStreamCommand for SkipWhile {
|
|||||||
registry: &CommandRegistry,
|
registry: &CommandRegistry,
|
||||||
) -> Result<OutputStream, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
let registry = registry.clone();
|
let registry = registry.clone();
|
||||||
|
let scope = args.call_info.scope.clone();
|
||||||
let call_info = args.evaluate_once(®istry)?;
|
let call_info = args.evaluate_once(®istry)?;
|
||||||
|
|
||||||
let block = call_info.args.expect_nth(0)?.clone();
|
let block = call_info.args.expect_nth(0)?.clone();
|
||||||
@ -80,7 +81,8 @@ impl WholeStreamCommand for SkipWhile {
|
|||||||
let objects = call_info.input.skip_while(move |item| {
|
let objects = call_info.input.skip_while(move |item| {
|
||||||
let condition = condition.clone();
|
let condition = condition.clone();
|
||||||
trace!("ITEM = {:?}", item);
|
trace!("ITEM = {:?}", item);
|
||||||
let result = evaluate_baseline_expr(&*condition, ®istry, &Scope::new(item.clone()));
|
let result =
|
||||||
|
evaluate_baseline_expr(&*condition, ®istry, &scope.clone().set_it(item.clone()));
|
||||||
trace!("RESULT = {:?}", result);
|
trace!("RESULT = {:?}", result);
|
||||||
|
|
||||||
let return_value = match result {
|
let return_value = match result {
|
||||||
|
@ -3,9 +3,7 @@ use crate::context::CommandRegistry;
|
|||||||
use crate::evaluate::evaluate_baseline_expr;
|
use crate::evaluate::evaluate_baseline_expr;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
use nu_protocol::{
|
use nu_protocol::{hir::Block, hir::ClassifiedCommand, ReturnSuccess, Signature, SyntaxShape};
|
||||||
hir::Block, hir::ClassifiedCommand, ReturnSuccess, Scope, Signature, SyntaxShape,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub struct Where;
|
pub struct Where;
|
||||||
|
|
||||||
@ -36,7 +34,7 @@ impl WholeStreamCommand for Where {
|
|||||||
args: CommandArgs,
|
args: CommandArgs,
|
||||||
registry: &CommandRegistry,
|
registry: &CommandRegistry,
|
||||||
) -> Result<OutputStream, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
args.process(registry, where_command)?.run()
|
Ok(args.process_raw(registry, where_command)?.run())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn where_command(
|
fn where_command(
|
||||||
@ -47,6 +45,7 @@ fn where_command(
|
|||||||
input,
|
input,
|
||||||
..
|
..
|
||||||
}: RunnableContext,
|
}: RunnableContext,
|
||||||
|
raw_args: RawCommandArgs,
|
||||||
) -> Result<OutputStream, ShellError> {
|
) -> Result<OutputStream, ShellError> {
|
||||||
let condition = {
|
let condition = {
|
||||||
if block.block.len() != 1 {
|
if block.block.len() != 1 {
|
||||||
@ -78,12 +77,12 @@ fn where_command(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut input = input;
|
let mut input = input;
|
||||||
|
let scope = raw_args.call_info.scope;
|
||||||
let stream = async_stream! {
|
let stream = async_stream! {
|
||||||
while let Some(input) = input.next().await {
|
while let Some(input) = input.next().await {
|
||||||
|
|
||||||
//FIXME: should we use the scope that's brought in as well?
|
//FIXME: should we use the scope that's brought in as well?
|
||||||
let condition = evaluate_baseline_expr(&condition, ®istry, &Scope::new(input.clone()))?;
|
let condition = evaluate_baseline_expr(&condition, ®istry, &scope.clone().set_it(input.clone()))?;
|
||||||
|
|
||||||
match condition.as_bool() {
|
match condition.as_bool() {
|
||||||
Ok(b) => {
|
Ok(b) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user