@@ -191,17 +191,16 @@ export function Run(
191
191
export const Switches = function ( switches : Record < string , any > ) {
192
192
// Default value for switches
193
193
switches = switches || { } ;
194
- var a = [ ] ;
194
+ let a = [ ] ;
195
195
// Set default values of boolean switches
196
196
switches . so = switches . so === true ? true : false ;
197
197
switches . spl = switches . spl === true ? true : false ;
198
198
switches . ssc = switches . ssc === false ? false : true ;
199
199
switches . ssw = switches . ssw === true ? true : false ;
200
200
switches . y = switches . y === false ? false : true ;
201
- var s ;
202
201
203
202
/*jshint forin:false*/
204
- for ( s in switches ) {
203
+ for ( const s in switches ) {
205
204
// Switches that are set or not. Just add them to the array if they are
206
205
// present. Differ the `ssc` switch treatment to later in the function.
207
206
if ( switches [ s ] === true && s !== 'ssc' ) {
@@ -212,19 +211,16 @@ export const Switches = function (switches: Record<string, any>) {
212
211
// wrap the value with double quotes. Else just add the switch and its value
213
212
// to the string. Doubles quotes are used for parsing with a RegExp later.
214
213
if ( ! isBool ( switches [ s ] ) ) {
215
- // Special treatment for wildcards
216
214
if ( s === 'wildcards' ) {
215
+ // Special treatment for wildcards
217
216
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 ] ;
226
221
} else {
227
- a . push ( '-' + s + '"' + switches [ s ] + '"' ) ;
222
+ const quote = switches [ s ] . includes ( ' ' ) ? '"' : '' ;
223
+ a . push ( `-${ s } ${ quote } ${ switches [ s ] } ${ quote } ` ) ;
228
224
}
229
225
}
230
226
0 commit comments