Skip to content

Commit 8b1a13a

Browse files
committed
make some parts of Run function more compact (utility.ts)
1 parent f3adee7 commit 8b1a13a

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

src/utility.ts

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -118,38 +118,25 @@ export function Run(
118118
}
119119

120120
if (switches.files) {
121-
let files = switches.files;
121+
const files = switches.files;
122122
delete switches.files;
123123

124-
if (Array.isArray(files)) {
125-
files.forEach(function (s) {
126-
args.push(s);
127-
});
128-
} else {
129-
args.push(files);
130-
}
131-
132-
args.push('-r');
133-
args.push('-aoa');
124+
const filesArray = Array.isArray(files) ? files : [files];
125+
args = [...args, ...filesArray, '-r', '-aoa'];
134126
}
135127

136128
// Add switches to the `args` array.
137129
let switchesArray = Switches(switches);
138-
switchesArray.forEach(function (s) {
139-
args.push(s);
140-
});
141-
// Remove now double quotes. If present in the spawned process 7-Zip will
142-
// read them as part of the paths (e.g.: create a `"archive.7z"` with
143-
// quotes in the file-name);
144-
args.forEach(function (e, i) {
145-
if (!isString(e)) {
146-
return;
147-
}
130+
args = [...args, ...switchesArray];
148131

149-
if (e.substr(0, 1) !== '-') {
150-
e = e.replace(/^"/, '');
151-
e = e.replace(/"$/, '');
152-
args[i] = e;
132+
// Remove double quotes. If present in the spawned process, 7-Zip will
133+
// read them as part of the path (e.g.: create a `"archive.7z"` with
134+
// quotes in the file-name);
135+
args.forEach(function (arg, i) {
136+
if (!isString(arg)) return;
137+
const doubleQuotesMatch = arg.match(/^\"(.+)\"$/);
138+
if (doubleQuotesMatch) {
139+
args[i] = doubleQuotesMatch[1];
153140
}
154141
});
155142
// Add bb2 to args array so we get file info

0 commit comments

Comments
 (0)