-
Notifications
You must be signed in to change notification settings - Fork 287
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
pkg/tool/exec: Correctly parse and join cmd args #3238
Comments
That is indeed a bug no matter what; if the input command was
Just so I understand, why do you want to use the string form when the list form exists? Quoting my reply from #3207 (comment) to join the threads:
It seems to me like deprecating the
|
The command is expected to fail, as we run the "false" program which always fails and ignores any arguments. The printed error is ambiguous, as it's not possible to see what the original list of arguments was, hence the TODO. The following commit will resolve this bug. For #3238. Signed-off-by: Daniel Martí <[email protected]> Change-Id: Ie277772ce58dfac48df9440e0a53fd9f1fc309cc Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1197451 Reviewed-by: Roger Peppe <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
If we render the command arguments as a quoted Go string joining the arguments via spaces, it's always going to be confusing if any of those arguments contain any spaces. We always use a slice now, even when the arguments don't contain any spaces or even when there's just one argument, but consistency seems more important than saving a few characters. An alternative to Go slices with %q quoting, following Go syntax, would be to quote a list of strings in CUE syntax. However, we use Go syntax for lists and string quoting for errors rather consistently, so it seems best to continue doing so here. While here, add a godoc for mkCommand, avoid doing a lookup on the "cmd" field twice, and simplify the code slightly. Updates #3238. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I1a2ae4e0c07236db566ddc9217c1722bb5e99da4 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1197452 Reviewed-by: Roger Peppe <[email protected]> Unity-Result: CUE porcuepine <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
For the time being, I've marked this issue as resolved by making the error messages non-ambiguous, and clearly documenting how the string form works with splitting arguments and its limitation. If this is still confusing to users, we can look into more agressive measures such as deprecating or even removing the string form in favor of the list form, with a rewrite in Let me know if that makes sense, or if you'd like to reopen this issue to discuss anything else. I'll close the PR for the time being as well, because like I said, we don't intend to add shell quoting support to the tool/exec package. |
I'm frustrated that the string form of
tool/exec.Run.cmd
does not parse args correctly, and that when it prints a command after it exits with an error status it incorrectly joins the args so it is not possible to simply copy the printed command and run it manually. The string form is nice to use for the simple case of running a single command, but it fails to correctly parse the args even if they are appropriately quoted. Also it fails to correctly print out debug information about a command that failed, as it uses plain concatenation instead of properly quoting arguments with spaces or special characters, even if they were passed as separate args in the list form.For example, consider the following tool file:
The
parse
command fails because tool/exec incorrectly parses the final quoted arg as a multiple args. Thejoin
command fails intentionally, but the printed error is incorrect, since the stringbash -c echo hello world; exit 1
is not the same command as what cue cmd ran.I'd like tool/exec to correctly parse args in the string form and correctly join args in both forms for debug printing. This can be implemented by importing the venerate
github.com/kballard/go-shellquote
library and updating the code to use it for splitting / joining instead ofstrings.Fields
/ plain concatenation. I have implemented this approach in PR #3207 which also includes new tests for these cases and more.Some alternatives:
tool/exec.ParseArgs
/JoinArgs
), and refactor the Run tool to perform the parsing/joining via the new tools within cue instead.The text was updated successfully, but these errors were encountered: