Fixes #412 Make it easier to construct simple Bash commands #413
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Context:
This aims to make it easier for plugins to construct simple, parameterized Bash commands, without having to worry about escaping, quoting, or special characters.
Problem:
Suppose a plugin wants to construct a very simple Bash command line, with a command and some parameters that are based on data provided by the user. For example, if a user provisions a new VDB named
foo
, then maybe the plugin wants to place a sentinel file somewhere on a remote host, something like this:The plugin code to do this might look like this:
Okay, so now imagine the name of the VDB is "Bob's $10B idea". The Bash command constructed will be:
This is a syntax error. In order to do this properly, the plugin has to take special care to quote/escape that single-quote in
Bob's
, and also that dollar sign.It's very easy to forget to do this (in fact, our docs have this problem!). This work is fairly fussy and error-prone, and really is not something a plugin should have to deal with just to run a simple command.
Solution:
Provide a function which will construct a valid Bash string, if given the name of a command and a set of arguments to that command. The passed-in strings will be quoted/escaped as necessary such that the command sees the same string contents that the plugin code does... even if those strings contain special characters.
Testing
I wrote a number of unit test cases (included in this PR)
I also hand-tested the code by copy/pasting results directly to a Bash prompt.
I did not have time to do any testing with a real plugin or a real engine. And, I will stop having access to engines very soon, so I will not be able to do any such testing in future either.
Implementation:
See code/comments
Notes To Reviewers:
I'm losing access to this github account soon, and will not be able to make modifications to this PR, nor to respond to any feedback.
Feel free to do whatever you want with this: