Skip to content

Commit 516736f

Browse files
committed
Reusable function to append suffix parameters
1 parent 2ab1936 commit 516736f

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

simple-git/src/lib/plugins/suffix-paths.plugin.ts

+8-10
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,30 @@ export function suffixPathsPlugin(): SimpleGitPlugin<'spawn.args'> {
66
type: 'spawn.args',
77
action(data) {
88
const prefix: string[] = [];
9-
const suffix: string[] = [];
10-
let suffixFound: boolean = false;
9+
let suffix: undefined | string[];
10+
function append(args: string[]) {
11+
(suffix = suffix || []).push(...args);
12+
}
1113

1214
for (let i = 0; i < data.length; i++) {
1315
const param = data[i];
1416

1517
if (isPathSpec(param)) {
16-
suffixFound = true;
17-
suffix.push(...toPaths(param));
18+
append(toPaths(param));
1819
continue;
1920
}
2021

2122
if (param === '--') {
22-
suffixFound = true;
23-
suffix.push(
24-
...data
25-
.slice(i + 1)
26-
.flatMap((item) => (isPathSpec(item) && toPaths(item)) || item)
23+
append(
24+
data.slice(i + 1).flatMap((item) => (isPathSpec(item) && toPaths(item)) || item)
2725
);
2826
break;
2927
}
3028

3129
prefix.push(param);
3230
}
3331

34-
return suffixFound ? [...prefix, '--', ...suffix.map(String)] : prefix;
32+
return !suffix ? prefix : [...prefix, '--', ...suffix.map(String)];
3533
},
3634
};
3735
}

0 commit comments

Comments
 (0)