cli/src/commands/repo-create.tsblame
View source
59e66671import { spinner, log } from "@clack/prompts";
e93a9782import { hubRequest } from "../api.js";
e93a9783
e93a9784interface Repo {
e93a9785 id: number;
e93a9786 owner_name: string;
e93a9787 name: string;
e93a9788 description: string | null;
e93a9789 default_branch: string;
e93a97810}
e93a97811
e93a97812export async function repoCreate(args: string[]) {
e93a97813 const name = args.find((a) => !a.startsWith("--"));
e93a97814 if (!name) {
59e666715 log.error("Usage: grove repo create <name> [--description <desc>] [--branch <branch>]");
e93a97816 process.exit(1);
e93a97817 }
e93a97818
e93a97819 const descIdx = args.indexOf("--description");
e93a97820 const description = descIdx !== -1 ? args[descIdx + 1] : undefined;
e93a97821
e93a97822 const branchIdx = args.indexOf("--branch");
e93a97823 const default_branch = branchIdx !== -1 ? args[branchIdx + 1] : undefined;
e93a97824
59129ad25 const ownerIdx = args.indexOf("--owner");
59129ad26 const owner = ownerIdx !== -1 ? args[ownerIdx + 1] : undefined;
59129ad27
0d9d72328 const is_private = args.includes("--private");
59129ad29 const skip_seed = args.includes("--no-seed");
59129ad30
59e666731 const s = spinner();
59e666732 s.start(`Creating repository '${name}'`);
e93a97833 const { repo } = await hubRequest<{ repo: Repo }>("/api/repos", {
e93a97834 method: "POST",
0d9d72335 body: JSON.stringify({ name, description, default_branch, owner, is_private, skip_seed }),
e93a97836 });
59e666737 s.stop(`Created repository: ${repo.owner_name}/${repo.name}`);
e93a97838}