forked from extern/nushell
fix argument type (#5695)
* fix argument type * while run external, convert list argument to str * fix argument converting logic * using parse_list_expression instead of parse_full_cell_path * make parsing logic more explicit * revert changes * add tests
This commit is contained in:
parent
17a5aa3052
commit
75b2d26187
@ -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::<Vec<Result<Spanned<String>, ShellError>>>(),
|
||||
val => vec![value_as_spanned(val)],
|
||||
})
|
||||
.collect::<Result<Vec<Spanned<String>>, 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,
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user