diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-21 15:52:04 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-02-21 15:52:04 +0100 |
commit | a446deaff32714c81fb02c7138de48fafa8216c8 (patch) | |
tree | 43182c672cbc25754f5ba5274f9b8be6da2f251b /lib/utils | |
parent | e5dd987d038e93d424a65038046723531c2519b3 (diff) | |
download | gitbook-a446deaff32714c81fb02c7138de48fafa8216c8.zip gitbook-a446deaff32714c81fb02c7138de48fafa8216c8.tar.gz gitbook-a446deaff32714c81fb02c7138de48fafa8216c8.tar.bz2 |
Complete generator for ebooks
Diffstat (limited to 'lib/utils')
-rw-r--r-- | lib/utils/command.js | 22 |
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 }; |