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
|
let mut spanned_args = vec![];
|
||||||
.into_iter()
|
for one_arg in args {
|
||||||
.flat_map(|arg| match arg {
|
match one_arg {
|
||||||
Value::List { vals, .. } => vals
|
Value::List { vals, .. } => {
|
||||||
.into_iter()
|
// turn all the strings in the array into params.
|
||||||
.map(value_as_spanned)
|
// Example: one_arg may be something like ["ls" "-a"]
|
||||||
.collect::<Vec<Result<Spanned<String>, ShellError>>>(),
|
// convert it to "ls" "-a"
|
||||||
val => vec![value_as_spanned(val)],
|
for v in vals {
|
||||||
})
|
spanned_args.push(value_as_spanned(v)?)
|
||||||
.collect::<Result<Vec<Spanned<String>>, ShellError>>()?;
|
}
|
||||||
|
}
|
||||||
|
val => spanned_args.push(value_as_spanned(val)?),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let command = ExternalCommand {
|
let command = ExternalCommand {
|
||||||
name,
|
name,
|
||||||
args,
|
args: spanned_args,
|
||||||
redirect_stdout,
|
redirect_stdout,
|
||||||
redirect_stderr,
|
redirect_stderr,
|
||||||
env_vars: env_vars_str,
|
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);
|
let (arg, err) = parse_dollar_expr(working_set, *span, expand_aliases_denylist);
|
||||||
error = error.or(err);
|
error = error.or(err);
|
||||||
args.push(arg);
|
args.push(arg);
|
||||||
} else if contents.starts_with(b"(") {
|
} else if contents.starts_with(b"[") {
|
||||||
let (arg, err) =
|
let (arg, err) = parse_list_expression(
|
||||||
parse_full_cell_path(working_set, None, *span, expand_aliases_denylist);
|
working_set,
|
||||||
|
*span,
|
||||||
|
&SyntaxShape::Any,
|
||||||
|
expand_aliases_denylist,
|
||||||
|
);
|
||||||
error = error.or(err);
|
error = error.or(err);
|
||||||
args.push(arg);
|
args.push(arg);
|
||||||
} else {
|
} else {
|
||||||
|
@ -306,6 +306,30 @@ mod nu_commands {
|
|||||||
|
|
||||||
assert_eq!(actual.out, "");
|
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 {
|
mod nu_script {
|
||||||
|
Loading…
Reference in New Issue
Block a user