diff --git a/crates/nu-command/src/system/run_external.rs b/crates/nu-command/src/system/run_external.rs index 14c02806a..b4a35ffa1 100644 --- a/crates/nu-command/src/system/run_external.rs +++ b/crates/nu-command/src/system/run_external.rs @@ -69,20 +69,24 @@ impl Command for External { }) } - let args = args - .into_iter() - .flat_map(|arg| match arg { - Value::List { vals, .. } => vals - .into_iter() - .map(value_as_spanned) - .collect::, ShellError>>>(), - val => vec![value_as_spanned(val)], - }) - .collect::>, ShellError>>()?; + let mut spanned_args = vec![]; + for one_arg in args { + match one_arg { + Value::List { vals, .. } => { + // turn all the strings in the array into params. + // Example: one_arg may be something like ["ls" "-a"] + // convert it to "ls" "-a" + for v in vals { + spanned_args.push(value_as_spanned(v)?) + } + } + val => spanned_args.push(value_as_spanned(val)?), + } + } let command = ExternalCommand { name, - args, + args: spanned_args, redirect_stdout, redirect_stderr, env_vars: env_vars_str, diff --git a/crates/nu-parser/src/parser.rs b/crates/nu-parser/src/parser.rs index d3506dc72..873fbd184 100644 --- a/crates/nu-parser/src/parser.rs +++ b/crates/nu-parser/src/parser.rs @@ -294,9 +294,13 @@ pub fn parse_external_call( let (arg, err) = parse_dollar_expr(working_set, *span, expand_aliases_denylist); error = error.or(err); args.push(arg); - } else if contents.starts_with(b"(") { - let (arg, err) = - parse_full_cell_path(working_set, None, *span, expand_aliases_denylist); + } else if contents.starts_with(b"[") { + let (arg, err) = parse_list_expression( + working_set, + *span, + &SyntaxShape::Any, + expand_aliases_denylist, + ); error = error.or(err); args.push(arg); } else { diff --git a/tests/shell/pipeline/commands/external.rs b/tests/shell/pipeline/commands/external.rs index 4c0257e3e..1c351f774 100644 --- a/tests/shell/pipeline/commands/external.rs +++ b/tests/shell/pipeline/commands/external.rs @@ -306,6 +306,30 @@ mod nu_commands { assert_eq!(actual.out, ""); } + + #[test] + fn command_list_arg_test() { + let actual = nu!(cwd: ".", r#" + nu ['-c' 'version'] + "#); + + assert!(actual.out.contains("version")); + assert!(actual.out.contains("rust_version")); + assert!(actual.out.contains("rust_channel")); + assert!(actual.out.contains("pkg_version")); + } + + #[test] + fn command_cell_path_arg_test() { + let actual = nu!(cwd: ".", r#" + nu ([ '-c' 'version' ]) + "#); + + assert!(actual.out.contains("version")); + assert!(actual.out.contains("rust_version")); + assert!(actual.out.contains("rust_channel")); + assert!(actual.out.contains("pkg_version")); + } } mod nu_script {