diff --git a/crates/nu-cli/src/commands/classified/block.rs b/crates/nu-cli/src/commands/classified/block.rs index fb8777bc90..fc40826d13 100644 --- a/crates/nu-cli/src/commands/classified/block.rs +++ b/crates/nu-cli/src/commands/classified/block.rs @@ -1,5 +1,5 @@ use crate::commands::classified::expr::run_expression_block; -use crate::commands::classified::external::run_external_command; +//use crate::commands::classified::external::run_external_command; use crate::commands::classified::internal::run_internal_command; use crate::context::Context; use crate::prelude::*; @@ -81,14 +81,6 @@ async fn run_pipeline( run_internal_command(left, ctx, input, scope)? } - (Some(ClassifiedCommand::External(left)), None) => { - run_external_command(left, ctx, input, scope, true).await? - } - - (Some(ClassifiedCommand::External(left)), _) => { - run_external_command(left, ctx, input, scope, false).await? - } - (None, _) => break, }; } diff --git a/crates/nu-cli/src/commands/classified/pipeline.rs b/crates/nu-cli/src/commands/classified/pipeline.rs deleted file mode 100644 index 9174ea8d34..0000000000 --- a/crates/nu-cli/src/commands/classified/pipeline.rs +++ /dev/null @@ -1,50 +0,0 @@ -use crate::commands::classified::expr::run_expression_block; -use crate::commands::classified::external::run_external_command; -use crate::commands::classified::internal::run_internal_command; -use crate::context::Context; -use crate::stream::InputStream; -use nu_errors::ShellError; -use nu_protocol::hir::{ClassifiedCommand, ClassifiedPipeline}; -use nu_protocol::Scope; - -pub(crate) async fn run_pipeline( - pipeline: ClassifiedPipeline, - ctx: &mut Context, - mut input: InputStream, - scope: &Scope, -) -> Result { - let mut iter = pipeline.commands.list.into_iter().peekable(); - - loop { - let item: Option = iter.next(); - let next: Option<&ClassifiedCommand> = iter.peek(); - - input = match (item, next) { - (Some(ClassifiedCommand::Dynamic(_)), _) | (_, Some(ClassifiedCommand::Dynamic(_))) => { - return Err(ShellError::unimplemented("Dynamic commands")) - } - - (Some(ClassifiedCommand::Expr(expr)), _) => { - run_expression_block(*expr, ctx, input, scope)? - } - (Some(ClassifiedCommand::Error(err)), _) => return Err(err.into()), - (_, Some(ClassifiedCommand::Error(err))) => return Err(err.clone().into()), - - (Some(ClassifiedCommand::Internal(left)), _) => { - run_internal_command(left, ctx, input, scope)? - } - - (Some(ClassifiedCommand::External(left)), None) => { - run_external_command(left, ctx, input, scope, true).await? - } - - (Some(ClassifiedCommand::External(left)), _) => { - run_external_command(left, ctx, input, scope, false).await? - } - - (None, _) => break, - }; - } - - Ok(input) -} diff --git a/crates/nu-cli/src/commands/each.rs b/crates/nu-cli/src/commands/each.rs index bd621fb119..8207c0e921 100644 --- a/crates/nu-cli/src/commands/each.rs +++ b/crates/nu-cli/src/commands/each.rs @@ -55,13 +55,6 @@ impl PerItemCommand for Each { ).await; match result { - Ok(stream) if stream.is_empty() => { - yield Err(ShellError::labeled_error( - "Expected a block", - "each needs a block", - tag, - )); - } Ok(mut stream) => { let errors = context.get_errors(); if let Some(error) = errors.first() { diff --git a/crates/nu-cli/src/commands/run_external.rs b/crates/nu-cli/src/commands/run_external.rs index 7abdc47c06..375ea036d6 100644 --- a/crates/nu-cli/src/commands/run_external.rs +++ b/crates/nu-cli/src/commands/run_external.rs @@ -63,15 +63,15 @@ impl WholeStreamCommand for RunExternalCommand { let command = ExternalCommand { name, - name_tag: Tag::unknown(), + name_tag: args.call_info.name_tag.clone(), args: ExternalArgs { list: command_args .map(|arg| ExternalArg { arg: spanned_expression_to_string(arg), - tag: Tag::unknown(), + tag: Tag::unknown_anchor(arg.span), }) .collect(), - span: Default::default(), + span: args.call_info.args.span, }, }; diff --git a/crates/nu-parser/src/parse.rs b/crates/nu-parser/src/parse.rs index 0acbb44d6b..e02aa9cb26 100644 --- a/crates/nu-parser/src/parse.rs +++ b/crates/nu-parser/src/parse.rs @@ -422,7 +422,13 @@ fn parse_arg( Err(e) => return (garbage(lite_arg.span), Some(e)), }; - if lite_block.block.len() != 1 { + if lite_block.block.is_empty() { + return ( + SpannedExpression::new(Expression::List(vec![]), lite_arg.span), + error, + ); + } + if lite_block.block.len() > 1 { return ( garbage(lite_arg.span), Some(ParseError::mismatch("table", lite_arg.clone())), @@ -1006,7 +1012,7 @@ fn classify_pipeline( .name .clone() .map(|v| v.chars().skip(1).collect::()); - + let name_span = name.span; // TODO this is the same as the `else` branch below, only the name differs. Find a way // to share this functionality. let name_iter = std::iter::once(name); @@ -1015,11 +1021,11 @@ fn classify_pipeline( commands.push(ClassifiedCommand::Internal(InternalCommand { name: "run_external".to_string(), - name_span: Span::unknown(), + name_span, args: hir::Call { head: Box::new(SpannedExpression { expr: Expression::string("run_external".to_string()), - span: Span::unknown(), + span: name_span, }), positional: Some(args), named: None, @@ -1052,6 +1058,7 @@ fn classify_pipeline( let trimmed = trim_quotes(&v); expand_path(&trimmed) }); + let name_span = name.span; let name_iter = std::iter::once(name); let args = name_iter.chain(lite_cmd.args.clone().into_iter()); @@ -1059,11 +1066,11 @@ fn classify_pipeline( commands.push(ClassifiedCommand::Internal(InternalCommand { name: "run_external".to_string(), - name_span: Span::unknown(), + name_span, args: hir::Call { head: Box::new(SpannedExpression { expr: Expression::string("run_external".to_string()), - span: Span::unknown(), + span: name_span, }), positional: Some(args), named: None, diff --git a/crates/nu-parser/src/shapes.rs b/crates/nu-parser/src/shapes.rs index 2b764272ae..d7ae07b729 100644 --- a/crates/nu-parser/src/shapes.rs +++ b/crates/nu-parser/src/shapes.rs @@ -92,12 +92,6 @@ pub fn shapes(commands: &Block) -> Vec> { } } } - ClassifiedCommand::External(external) => { - output.push(FlatShape::ExternalCommand.spanned(external.name_tag.span)); - for arg in external.args.iter() { - output.push(FlatShape::ExternalWord.spanned(arg.tag.span)); - } - } ClassifiedCommand::Expr(expr) => output.append(&mut expression_to_flat_shape(expr)), _ => {} } diff --git a/crates/nu-protocol/src/hir.rs b/crates/nu-protocol/src/hir.rs index 4788a41433..3534589c6b 100644 --- a/crates/nu-protocol/src/hir.rs +++ b/crates/nu-protocol/src/hir.rs @@ -74,7 +74,6 @@ pub enum ClassifiedCommand { #[allow(unused)] Dynamic(crate::hir::Call), Internal(InternalCommand), - External(crate::hir::ExternalCommand), Error(ParseError), }