Skip to content

Fix bug with multiple input objects to an external command. - #829

Merged
sophiajt merged 1 commit into
nushell:masterfrom
thegedge:fix-multiple-values-for-external-command
Oct 14, 2019
Merged

sophiajt merged 1 commit into
nushell:masterfrom
thegedge:fix-multiple-values-for-external-command

Conversation

@thegedge

@thegedge thegedge commented Oct 14, 2019 •

Copy link
Copy Markdown
Contributor

Previously, we would build a command that looked something like this:

<ex_cmd> "$it" "&&" "<ex_cmd>" "$it"

So that the "&&" and "<ex_cmd>" would also be arguments to the command, instead of the original intent of chaining commands together (edit: so you can imaging the command cat would try to look for a file called &&).

This PR adds a few things:

  • Builds up a command string that can be passed to an external shell.
  • Adds nu_combined! macro for tests, so we can assert against both stdout and stderr.
  • Adds a test to verify correct behaviour.

@gitpod-io

gitpod-io Bot commented Oct 14, 2019 •

Copy link
Copy Markdown

process = process.arg(&arg.replace("$it", &i.as_string()?));
}
}
format!("{} {}", self.name, itertools::join(args, " "))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is perhaps the biggest point of discussion. Not sure if there's some escaping I'd have to do here to ensure the joined command below will be executed correctly by the shell.


process = Exec::shell(itertools::join(commands, " && "))
} else {
process = Exec::cmd(&self.name);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One other thing I noticed here is that we seem to handle arguments here differently than above (stripping quotes). Should stripping quotes be handled at a different layer?

Previously, we would build a command that looked something like this:

  <ex_cmd> "$it" "&&" "<ex_cmd>" "$it"

So that the "&&" and "<ex_cmd>" would also be arguments to the command,
instead of a chained command. This commit builds up a command string
that can be passed to an external shell.
@thegedge

Copy link
Copy Markdown
Contributor Author

Okay, linting errors fixed. Ready for review!

@sophiajt

Copy link
Copy Markdown
Contributor

Your timing is excellent, we were just talking about getting around to fixing this today.

Thanks for the fix!

@sophiajt
sophiajt merged commit f858a12 into nushell:master Oct 14, 2019
@thegedge
thegedge deleted the fix-multiple-values-for-external-command branch October 15, 2019 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants