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

Function runConfig

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

Source from the content-addressed store, hash-verified

1859// ---------------------------------------------------------------
1860
1861async function runConfig(
1862 client: GitClient,
1863 args: string[],
1864 input: GitCliInput,
1865): Promise<GitCliResult> {
1866 // `git config <key>` -> get
1867 // `git config --get-all <key>` -> get all values
1868 // `git config <key> <value>` -> set
1869 // `git config --add <key> <value>`-> append multi-valued
1870 // `git config --unset <key>` -> unset
1871 const parsed = parseFlags(args, {
1872 get: { kind: "bool" },
1873 "get-all": { kind: "bool" },
1874 add: { kind: "bool" },
1875 unset: { kind: "bool" },
1876 });
1877 if ("error" in parsed) {
1878 return { stdout: "", stderr: `git config: ${parsed.error}\n`, exitCode: 129 };
1879 }
1880 const dir = resolveDir(undefined, input.cwd);
1881 const getAll = parsed.flags["get-all"] === true;
1882 const wantUnset = parsed.flags.unset === true;
1883 const wantAdd = parsed.flags.add === true;
1884
1885 if (wantUnset) {
1886 if (parsed.positional.length !== 1) {
1887 return {
1888 stdout: "",
1889 stderr: "git config: usage: git config --unset <key>\n",
1890 exitCode: 129,
1891 };
1892 }
1893 try {
1894 await client.configSet({ dir, path: parsed.positional[0], value: undefined });
1895 return { stdout: "", stderr: "", exitCode: 0 };
1896 } catch (cause) {
1897 return mapGitError("config", cause);
1898 }
1899 }
1900
1901 if (parsed.positional.length === 1) {
1902 // Get mode.
1903 try {
1904 const value = await client.configGet({
1905 dir,
1906 path: parsed.positional[0],
1907 all: getAll,
1908 });
1909 if (value === undefined) {
1910 // Real git exits 1 with no output when --get misses.
1911 return { stdout: "", stderr: "", exitCode: 1 };
1912 }
1913 const text = Array.isArray(value) ? `${value.join("\n")}\n` : `${value}\n`;
1914 return { stdout: text, stderr: "", exitCode: 0 };
1915 } catch (cause) {
1916 return mapGitError("config", cause);
1917 }
1918 }

Callers 1

runGitCliFunction · 0.85

Calls 5

resolveDirFunction · 0.85
mapGitErrorFunction · 0.85
configSetMethod · 0.80
configGetMethod · 0.80
parseFlagsFunction · 0.70

Tested by

no test coverage detected