Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix argument type #5695

Merged
merged 7 commits into from
Jun 6, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions crates/nu-command/src/system/run_external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?),
}
}
kubouch marked this conversation as resolved.
Show resolved Hide resolved
WindSoilder marked this conversation as resolved.
Show resolved Hide resolved

let command = ExternalCommand {
name,
args,
args: spanned_args,
redirect_stdout,
redirect_stderr,
env_vars: env_vars_str,
Expand Down
11 changes: 10 additions & 1 deletion crates/nu-parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ pub fn parse_external_call(
for span in &spans[1..] {
let contents = working_set.get_span_contents(*span);

if contents.starts_with(b"$") || contents.starts_with(b"(") {
WindSoilder marked this conversation as resolved.
Show resolved Hide resolved
if contents.starts_with(b"$") {
let (arg, err) = parse_dollar_expr(working_set, *span, expand_aliases_denylist);
error = error.or(err);
args.push(arg);
Expand All @@ -299,6 +299,15 @@ pub fn parse_external_call(
parse_full_cell_path(working_set, None, *span, expand_aliases_denylist);
WindSoilder marked this conversation as resolved.
Show resolved Hide resolved
error = error.or(err);
args.push(arg);
} else if contents.starts_with(b"[") {
WindSoilder marked this conversation as resolved.
Show resolved Hide resolved
let (arg, err) = parse_list_expression(
working_set,
*span,
&SyntaxShape::Any,
expand_aliases_denylist,
);
error = error.or(err);
args.push(arg);
} else {
let (contents, err) = unescape_unquote_string(contents, *span);
error = error.or(err);
Expand Down