MCPcopy Create free account
hub / github.com/steveukx/git-js / parseTaskFlags

Function parseTaskFlags

packages/argv-parser/src/flags/parse-task-flags.ts:13–75  ·  view source on GitHub ↗
(
   tokens: readonly unknown[],
   task: string | null,
   flags: Flag[] = []
)

Source from the content-addressed store, hash-verified

11};
12
13export function parseTaskFlags(
14 tokens: readonly unknown[],
15 task: string | null,
16 flags: Flag[] = []
17): TaskFlags {
18 const spec = getFlagSpecForTask(task);
19 const positionals: string[] = [];
20 const pathspecs: string[] = [];
21
22 let i = 0;
23 while (i < tokens.length) {
24 const current = tokens[i];
25
26 if (isPathSpec(current)) {
27 pathspecs.push(...toPaths(current as string));
28 i++;
29 continue;
30 }
31
32 const raw = String(current);
33
34 if (raw === '--') {
35 for (let j = i + 1; j < tokens.length; j++) {
36 const t = tokens[j];
37 isPathSpec(t) ? pathspecs.push(...toPaths(t as string)) : pathspecs.push(String(t));
38 }
39 break;
40 }
41
42 if (!raw.startsWith('-') || raw.length < 2) {
43 positionals.push(raw);
44 i++;
45 continue;
46 }
47
48 const parsed = expandToken(raw, spec);
49 let next = i + 1;
50
51 for (const token of parsed) {
52 const flag: Flag = {
53 name: token.name,
54 value: token.value,
55 absorbedNext: false,
56 isGlobal: false,
57 };
58 if (
59 token.needsNext &&
60 flag.value === undefined &&
61 next < tokens.length &&
62 !isPathSpec(tokens[next])
63 ) {
64 flag.value = String(tokens[next]);
65 flag.absorbedNext = true;
66 next++;
67 }
68 flags.push(flag);
69 }
70

Callers 1

parseArgvFunction · 0.90

Calls 5

getFlagSpecForTaskFunction · 0.90
isPathSpecFunction · 0.90
toPathsFunction · 0.90
expandTokenFunction · 0.90
pushMethod · 0.65

Tested by

no test coverage detected