summaryrefslogtreecommitdiffstats
path: root/lib/utils/command.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils/command.js')
-rw-r--r--lib/utils/command.js22
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/utils/command.js b/lib/utils/command.js
index c3e33c7..49b0998 100644
--- a/lib/utils/command.js
+++ b/lib/utils/command.js
@@ -1,3 +1,4 @@
+var _ = require('lodash');
var childProcess = require('child_process');
var Promise = require('./promise');
@@ -37,8 +38,27 @@ function spawn(command, args, options) {
return d.promise;
}
+// Transform an option object to a command line string
+function escapeShellArg(s) {
+ s = s.replace(/"/g, '\\"');
+ return '"' + s + '"';
+}
+
+function optionsToShellArgs(options) {
+ return _.chain(options)
+ .map(function(value, key) {
+ if (value === null || value === undefined || value === false) return null;
+ if (value === true) return key;
+ return key + '=' + escapeShellArg(value);
+ })
+ .compact()
+ .value()
+ .join(' ');
+}
+
module.exports = {
isAvailable: isAvailable,
exec: exec,
- spawn: spawn
+ spawn: spawn,
+ optionsToShellArgs: optionsToShellArgs
};