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

Function runClean

packages/computer/src/git/cli.ts:2069–2110  ·  view source on GitHub ↗
(
  client: GitClient,
  args: string[],
  input: GitCliInput,
)

Source from the content-addressed store, hash-verified

2067// ---------------------------------------------------------------
2068
2069async function runClean(
2070 client: GitClient,
2071 args: string[],
2072 input: GitCliInput,
2073): Promise<GitCliResult> {
2074 // `git clean -f [-d] [-n|--dry-run]`. Real git refuses to act
2075 // without `-f`; mirror that so a bare `git clean` is a no-op
2076 // error rather than a destructive surprise. The flags are all
2077 // boolean, so expand any combined short cluster (`-fd`, `-fdn`)
2078 // into separate tokens before parsing.
2079 const expanded = expandShortBoolCluster(args, new Set(["f", "d", "n"]));
2080 const parsed = parseFlags(expanded, {
2081 force: { kind: "bool", alias: ["f"] },
2082 d: { kind: "bool" },
2083 "dry-run": { kind: "bool", alias: ["n"] },
2084 });
2085 if ("error" in parsed) {
2086 return { stdout: "", stderr: `git clean: ${parsed.error}\n`, exitCode: 129 };
2087 }
2088 const dryRun = parsed.flags["dry-run"] === true;
2089 if (parsed.flags.force !== true && !dryRun) {
2090 return {
2091 stdout: "",
2092 stderr: "git clean: refusing to clean without -f (or use -n to preview)\n",
2093 exitCode: 129,
2094 };
2095 }
2096 const dir = resolveDir(undefined, input.cwd);
2097 try {
2098 const removed = await client.clean({
2099 dir,
2100 directories: parsed.flags.d === true,
2101 dryRun,
2102 });
2103 if (removed.length === 0) return { stdout: "", stderr: "", exitCode: 0 };
2104 const verb = dryRun ? "Would remove" : "Removing";
2105 const lines = removed.map((p) => `${verb} ${p}`);
2106 return { stdout: `${lines.join("\n")}\n`, stderr: "", exitCode: 0 };
2107 } catch (cause) {
2108 return mapGitError("clean", cause);
2109 }
2110}
2111
2112// ---------------------------------------------------------------
2113// shared error mapping

Callers 1

runGitCliFunction · 0.85

Calls 5

expandShortBoolClusterFunction · 0.85
resolveDirFunction · 0.85
mapGitErrorFunction · 0.85
cleanMethod · 0.80
parseFlagsFunction · 0.70

Tested by

no test coverage detected