summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/utils/command.js33
1 files changed, 26 insertions, 7 deletions
diff --git a/lib/utils/command.js b/lib/utils/command.js
index 083e72e..7311856 100644
--- a/lib/utils/command.js
+++ b/lib/utils/command.js
@@ -1,3 +1,4 @@
+var is = require('is');
var childProcess = require('child_process');
var spawn = require('spawn-cmd').spawn;
var Promise = require('./promise');
@@ -54,12 +55,29 @@ function spawnCmd(command, args, options) {
return d.promise;
}
-// Transform an option object to a command line string
-function escapeShellArg(s) {
- s = s.replace(/"/g, '\\"');
- return '"' + s + '"';
+/**
+ Transform an option object to a command line string
+
+ @param {String|number} value
+ @param {String}
+*/
+function escapeShellArg(value) {
+ if (is.number(value)) {
+ return value;
+ }
+
+ value = String(value);
+ value = value.replace(/"/g, '\\"');
+
+ return '"' + value + '"';
}
+/**
+ Transform a map of options into a command line arguments string
+
+ @param {Object} options
+ @return {String}
+*/
function optionsToShellArgs(options) {
var result = [];
@@ -69,11 +87,12 @@ function optionsToShellArgs(options) {
if (value === null || value === undefined || value === false) {
continue;
}
- if (value === true) {
+
+ if (is.bool(value)) {
result.push(key);
+ } else {
+ result.push(key + '=' + escapeShellArg(value));
}
-
- result.push(key + '=' + escapeShellArg(value));
}
return result.join(' ');