Skip to content

Commit 744d23e

Browse files
committed
make minor changes in Switches function (utility.ts)
1 parent 21fa30c commit 744d23e

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/utility.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -191,17 +191,16 @@ export function Run(
191191
export const Switches = function (switches: Record<string, any>) {
192192
// Default value for switches
193193
switches = switches || {};
194-
var a = [];
194+
let a = [];
195195
// Set default values of boolean switches
196196
switches.so = switches.so === true ? true : false;
197197
switches.spl = switches.spl === true ? true : false;
198198
switches.ssc = switches.ssc === false ? false : true;
199199
switches.ssw = switches.ssw === true ? true : false;
200200
switches.y = switches.y === false ? false : true;
201-
var s;
202201

203202
/*jshint forin:false*/
204-
for (s in switches) {
203+
for (const s in switches) {
205204
// Switches that are set or not. Just add them to the array if they are
206205
// present. Differ the `ssc` switch treatment to later in the function.
207206
if (switches[s] === true && s !== 'ssc') {
@@ -212,19 +211,16 @@ export const Switches = function (switches: Record<string, any>) {
212211
// wrap the value with double quotes. Else just add the switch and its value
213212
// to the string. Doubles quotes are used for parsing with a RegExp later.
214213
if (!isBool(switches[s])) {
215-
// Special treatment for wildcards
216214
if (s === 'wildcards') {
215+
// Special treatment for wildcards
217216
a.unshift(switches.wildcards);
218-
} // Allow raw switches to be added to the command, repeating switches like
219-
// -i is not possible otherwise.
220-
else if (s === 'raw') {
221-
switches.raw.forEach(function (rawValue: any) {
222-
a.push(rawValue);
223-
});
224-
} else if (switches[s].indexOf(' ') === -1) {
225-
a.push('-' + s + switches[s]);
217+
} else if (s === 'raw') {
218+
// Allow raw switches to be added to the command,
219+
// otherwise repeating switches like -i is not possible.
220+
a = [...a, ...switches.raw];
226221
} else {
227-
a.push('-' + s + '"' + switches[s] + '"');
222+
const quote = switches[s].includes(' ') ? '"' : '';
223+
a.push(`-${s}${quote}${switches[s]}${quote}`);
228224
}
229225
}
230226

0 commit comments

Comments
 (0)