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

Function runCreate

packages/computer/src/artifacts/cli.ts:104–214  ·  view source on GitHub ↗
(
  client: ArtifactClient,
  args: string[],
  remoteAdd: RemoteAddFn | undefined,
)

Source from the content-addressed store, hash-verified

102// `--force`, so a half-finished previous run has a clear recovery.
103
104async function runCreate(
105 client: ArtifactClient,
106 args: string[],
107 remoteAdd: RemoteAddFn | undefined,
108): Promise<ArtifactsCLIResult> {
109 const parsed = parseFlags(args, {
110 scope: { kind: "value" },
111 ttl: { kind: "value" },
112 remote: { kind: "value" },
113 "default-branch": { kind: "value" },
114 description: { kind: "value" },
115 force: { kind: "bool" },
116 });
117 if ("error" in parsed) return argvError("create", parsed.error);
118 const name = parsed.positional[0];
119 if (name === undefined) return argvError("create", "missing <name>");
120 if (parsed.positional.length > 1) {
121 return argvError("create", `unexpected argument '${parsed.positional[1]}'`);
122 }
123
124 // Scope defaults to write: the point of the shorthand is to set up a
125 // remote you can push to. A read default would register an origin
126 // that rejects the first push.
127 let scope: ArtifactScope = "write";
128 if (parsed.flags.scope !== undefined) {
129 const s = parsed.flags.scope as string;
130 if (s !== "read" && s !== "write") {
131 return argvError("create", `--scope must be 'read' or 'write' (got '${s}')`);
132 }
133 scope = s;
134 }
135
136 let ttl: number | undefined;
137 if (parsed.flags.ttl !== undefined) {
138 try {
139 ttl = parseDuration(parsed.flags.ttl as string);
140 } catch (cause) {
141 return argvError("create", cause instanceof Error ? cause.message : String(cause));
142 }
143 }
144
145 const force = parsed.flags.force === true;
146 const gitRemote = (parsed.flags.remote as string | undefined) ?? name;
147 const description = parsed.flags.description as string | undefined;
148 const setDefaultBranch = parsed.flags["default-branch"] as string | undefined;
149
150 // Step 1: create the repo, or adopt an existing one under --force.
151 // `get` and `create` return different shapes; only the fields the
152 // shorthand reports are needed, and both carry those.
153 let info: { name: string; remote: string; defaultBranch: string };
154 try {
155 const existing = await tryGet(client, name);
156 if (existing !== undefined) {
157 if (!force) {
158 return fail(
159 `artifacts create: repo '${name}' already exists; re-run with --force to reuse it and refresh the remote`,
160 );
161 }

Callers 1

runArtifactsCLIFunction · 0.85

Calls 12

argvErrorFunction · 0.85
parseDurationFunction · 0.85
tryGetFunction · 0.85
mapErrorFunction · 0.85
credentialURLFunction · 0.85
okFunction · 0.85
jsonFunction · 0.85
parseFlagsFunction · 0.70
failFunction · 0.70
remoteAddFunction · 0.70
createMethod · 0.65
createTokenMethod · 0.65

Tested by

no test coverage detected