1 | "use strict";
|
2 |
|
3 |
|
4 | const sprintf = require('util').format;
|
5 | const forIn = require('mout/object/forIn');
|
6 | const isArray = require('mout/lang/isArray');
|
7 | const compact = require('mout/array/compact');
|
8 |
|
9 | var fmt = (unix, k, v) => {
|
10 | if(v == undefined || v == null)
|
11 | return [];
|
12 | if(typeof v == "boolean" && v)
|
13 | return [sprintf("--%s", k)];
|
14 | return unix ? [sprintf("--%s", k), String(v)] : [sprintf("--%s=%s", k, String(v))];
|
15 | };
|
16 |
|
17 | module.exports = function(args, unix) {
|
18 | var cmds = [];
|
19 | forIn(args || {}, function (value, name) {
|
20 | var cmd = [];
|
21 | if(isArray(value))
|
22 | value.forEach(value => cmd.push.apply(cmd, fmt(unix, name, value)));
|
23 | else
|
24 | cmd = fmt(unix, name, value);
|
25 | cmds = cmds.concat(cmd);
|
26 | });
|
27 | cmds = compact(cmds);
|
28 | return cmds;
|
29 | };
|
30 |
|