-
-
Notifications
You must be signed in to change notification settings - Fork 313
/
suffix-paths.plugin.ts
34 lines (28 loc) · 934 Bytes
/
suffix-paths.plugin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { SimpleGitPlugin } from './simple-git-plugin';
import { isPathSpec, toPaths } from '../args/pathspec';
export function suffixPathsPlugin(): SimpleGitPlugin<'spawn.args'> {
return {
type: 'spawn.args',
action(data) {
const prefix: string[] = [];
const suffix: string[] = [];
for (let i = 0; i < data.length; i++) {
const param = data[i];
if (isPathSpec(param)) {
suffix.push(...toPaths(param));
continue;
}
if (param === '--') {
suffix.push(
...data
.slice(i + 1)
.flatMap((item) => (isPathSpec(item) && toPaths(item)) || item)
);
break;
}
prefix.push(param);
}
return !suffix.length ? prefix : [...prefix, '--', ...suffix.map(String)];
},
};
}