MCPcopy Create free account
hub / github.com/cloudflare/computer / parseGlobalOptions

Function parseGlobalOptions

packages/computer/src/git/cli.ts:2196–2219  ·  view source on GitHub ↗

* Pull leading global options off the front of argv. Only * `-C ` is supported today: it sets the working directory * the subcommand resolves its `dir` default against, matching * real git's top-level `-C`. A relative path joins onto the * current cwd. A second `-C` is rejected rather than

(
  argv: string[],
  cwd: string | undefined,
)

Source from the content-addressed store, hash-verified

2194 * agent use only needs one.
2195 */
2196function parseGlobalOptions(
2197 argv: string[],
2198 cwd: string | undefined,
2199): GlobalOptions | { error: string } {
2200 let cwdOut = cwd;
2201 let seenC = false;
2202 let i = 0;
2203 while (i < argv.length) {
2204 const arg = argv[i];
2205 if (arg === "-C") {
2206 if (seenC) return { error: "multiple -C options are not supported" };
2207 const value = argv[i + 1];
2208 if (value === undefined || value === "") {
2209 return { error: "option '-C' requires a value" };
2210 }
2211 cwdOut = value.startsWith("/") ? value : joinPath(cwdOut ?? "/", value);
2212 seenC = true;
2213 i += 2;
2214 continue;
2215 }
2216 break;
2217 }
2218 return { argv: argv.slice(i), cwd: cwdOut };
2219}
2220
2221function parseFlags(args: string[], spec: Record<string, FlagSpec>): ParseResult {
2222 const flags: Record<string, string | boolean> = {};

Callers 1

runGitCliFunction · 0.85

Calls 1

joinPathFunction · 0.70

Tested by

no test coverage detected