|
1 | 1 | import { log, note } from "@clack/prompts"; |
2 | | -import type { SubcommandDef } from "./subcommand-prompt"; |
3 | 2 | import { getToken } from "./auth"; |
4 | 3 | import { PlatformClient } from "./client"; |
| 4 | +import type { DomainArgs } from "./domain-args"; |
5 | 5 | import { readProjectConfig } from "./project"; |
6 | 6 | import { pc } from "./output"; |
7 | 7 |
|
8 | | -export const domainSubcommands: SubcommandDef[] = [ |
9 | | - { name: "add", arg: "<hostname>", description: "Add a custom domain" }, |
10 | | - { name: "delete", arg: "<hostname>", description: "Remove a custom domain" }, |
11 | | - { name: "list", description: "List custom domains + status" }, |
12 | | - { name: "status", arg: "<hostname>", description: "Check domain verification status" }, |
13 | | -]; |
14 | | - |
15 | | -export interface DomainArgs { |
16 | | - subcommand: "add" | "delete" | "list" | "status"; |
17 | | - hostname?: string; |
18 | | - projectSlug?: string; |
19 | | -} |
20 | | - |
21 | | -export function parseDomainArgs(args: string[]): DomainArgs { |
22 | | - const subcommand = args[0] as DomainArgs["subcommand"]; |
23 | | - if (!subcommand || !["add", "delete", "list", "status"].includes(subcommand)) { |
24 | | - throw new Error("Usage: void domain <add|delete|list|status> [hostname] [--project <name>]"); |
25 | | - } |
26 | | - |
27 | | - let hostname: string | undefined; |
28 | | - let projectSlug: string | undefined; |
29 | | - |
30 | | - const rest = args.slice(1); |
31 | | - for (let i = 0; i < rest.length; i++) { |
32 | | - if (rest[i] === "--project" && rest[i + 1]) { |
33 | | - projectSlug = rest[++i]; |
34 | | - } else if (!hostname) { |
35 | | - hostname = rest[i]; |
36 | | - } |
37 | | - } |
38 | | - |
39 | | - if ((subcommand === "add" || subcommand === "delete" || subcommand === "status") && !hostname) { |
40 | | - throw new Error(`Usage: void domain ${subcommand} <hostname> [--project <name>]`); |
41 | | - } |
42 | | - |
43 | | - return { subcommand, hostname, projectSlug }; |
44 | | -} |
45 | | - |
46 | 8 | export async function runDomainCommand(root: string, args: DomainArgs): Promise<void> { |
47 | 9 | const token = getToken(); |
48 | 10 | if (!token) { |
|
0 commit comments