MCPcopy Index your code
hub / github.com/garrytan/gstack / parseArgs

Function parseArgs

make-pdf/src/cli.ts:23–54  ·  view source on GitHub ↗
(argv: string[])

Source from the content-addressed store, hash-verified

21}
22
23function parseArgs(argv: string[]): ParsedArgs {
24 const args = argv.slice(2);
25 if (args.length === 0) {
26 printUsage();
27 process.exit(ExitCode.Success);
28 }
29
30 // First non-flag arg is the command.
31 let command = "";
32 const positional: string[] = [];
33 const flags: Record<string, string | boolean> = {};
34
35 for (let i = 0; i < args.length; i++) {
36 const a = args[i];
37 if (a.startsWith("--")) {
38 const key = a.slice(2);
39 const next = args[i + 1];
40 if (next !== undefined && !next.startsWith("--")) {
41 flags[key] = next;
42 i++;
43 } else {
44 flags[key] = true;
45 }
46 } else if (!command) {
47 command = a;
48 } else {
49 positional.push(a);
50 }
51 }
52
53 return { command, positional, flags };
54}
55
56function printUsage(): void {
57 const lines = [

Callers 1

mainFunction · 0.70

Calls 2

printUsageFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected