From 3bcc2aad805e51fe1ecac826a679b470a6cbb554 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20N=2E=20Robalino?= Date: Sun, 23 May 2021 19:30:30 -0500 Subject: [PATCH] Pass command's span correctly when reporting unexpected flags. (#3478) Not all lite command's first part denotes a real command (for cases like sub commands that it's second lite part accounts for the command name). This is important so that we can refer to it's span correctly. Here we fix to include the command's name span correctly whether it's a command or sub command when reporting missing flag errors. --- crates/nu-parser/src/parse.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/nu-parser/src/parse.rs b/crates/nu-parser/src/parse.rs index b5c1c57799..4aa18e0a00 100644 --- a/crates/nu-parser/src/parse.rs +++ b/crates/nu-parser/src/parse.rs @@ -1111,7 +1111,7 @@ fn parse_arg( /// This also allows users to provide a group of shorthand flags (-la) that correspond to multiple shorthand flags at once. fn get_flags_from_flag( signature: &nu_protocol::Signature, - cmd: &Spanned, + cmd: &InternalCommand, arg: &Spanned, ) -> (Vec<(String, NamedType)>, Option) { if arg.item.starts_with('-') { @@ -1128,7 +1128,7 @@ fn get_flags_from_flag( output.push((remainder.clone(), named_type.clone())); } else { error = Some(ParseError::argument_error( - cmd.clone(), + cmd.name.to_string().spanned(cmd.name_span), ArgumentError::UnexpectedFlag(arg.clone()), )); } @@ -1147,7 +1147,7 @@ fn get_flags_from_flag( if !found { error = Some(ParseError::argument_error( - cmd.clone(), + cmd.name.to_string().spanned(cmd.name_span), ArgumentError::UnexpectedFlag( arg.item .clone() @@ -1484,7 +1484,7 @@ fn parse_internal_command( while idx < lite_cmd.parts.len() { if lite_cmd.parts[idx].item.starts_with('-') && lite_cmd.parts[idx].item.len() > 1 { let (named_types, err) = - get_flags_from_flag(&signature, &lite_cmd.parts[0], &lite_cmd.parts[idx]); + get_flags_from_flag(&signature, &internal_command, &lite_cmd.parts[idx]); if err.is_none() { for (full_name, named_type) in &named_types {