1.2 KB39 lines
Blame
1import { spinner, log } from "@clack/prompts";
2import { hubRequest } from "../api.js";
3
4interface Repo {
5 id: number;
6 owner_name: string;
7 name: string;
8 description: string | null;
9 default_branch: string;
10}
11
12export async function repoCreate(args: string[]) {
13 const name = args.find((a) => !a.startsWith("--"));
14 if (!name) {
15 log.error("Usage: grove repo create <name> [--description <desc>] [--branch <branch>]");
16 process.exit(1);
17 }
18
19 const descIdx = args.indexOf("--description");
20 const description = descIdx !== -1 ? args[descIdx + 1] : undefined;
21
22 const branchIdx = args.indexOf("--branch");
23 const default_branch = branchIdx !== -1 ? args[branchIdx + 1] : undefined;
24
25 const ownerIdx = args.indexOf("--owner");
26 const owner = ownerIdx !== -1 ? args[ownerIdx + 1] : undefined;
27
28 const is_private = args.includes("--private");
29 const skip_seed = args.includes("--no-seed");
30
31 const s = spinner();
32 s.start(`Creating repository '${name}'`);
33 const { repo } = await hubRequest<{ repo: Repo }>("/api/repos", {
34 method: "POST",
35 body: JSON.stringify({ name, description, default_branch, owner, is_private, skip_seed }),
36 });
37 s.stop(`Created repository: ${repo.owner_name}/${repo.name}`);
38}
39