clone

push a directory of html from the terminal and get a four-character url back. a deno cli on cloudflare

feat/source-stable-push
nzip / cli / commands / site.ts
site.ts 3.4K
1import type { Config } from "../lib/config.ts";2import { fail } from "../lib/fmt.ts";3import { cmdCp } from "./cp.ts";4import { cmdPush } from "./push.ts";5import { cmdLs, cmdRevert, cmdRm, cmdSitePolicy, cmdSiteShow } from "./sites.ts";6import { cmdWhere } from "./where.ts";78export type SiteInvocation =9 | { kind: "push"; source?: string; target?: string }10 | { kind: "cp"; target?: string; dir?: string }11 | { kind: "show"; target?: string }12 | { kind: "policy"; target?: string }13 | { kind: "ls"; vault?: string }14 | { kind: "where"; target?: string }15 | { kind: "rm"; target?: string }16 | { kind: "revert"; target?: string };1718export function parseSiteInvocation(rest: string[]): SiteInvocation {19 const [action, first, second, ...extra] = rest;20 if (!action) fail("usage: nzip site <push|cp|show|policy|ls|where|rm|revert> ...");21 if (extra.length > 0) fail(`too many arguments for nzip site ${action}`);22 switch (action) {23 case "push":24 return { kind: "push", source: first, target: second };25 case "cp":26 return { kind: "cp", target: first, dir: second };27 case "show":28 if (second !== undefined) fail("usage: nzip site show <target>");29 return { kind: "show", target: first };30 case "policy":31 if (second !== undefined) fail("usage: nzip site policy <target> [options]");32 return { kind: "policy", target: first };33 case "update":34 return fail(35 "site update was replaced by site policy",36 "publish content with `nzip site push <dir|file> <target>`; change TTL/password with `nzip site policy <target> ...`",37 );38 case "ls":39 if (second !== undefined) fail("usage: nzip site ls [vault]");40 return { kind: "ls", vault: first };41 case "where":42 if (second !== undefined) fail("usage: nzip site where <target>");43 return { kind: "where", target: first };44 case "rm":45 if (second !== undefined) fail("usage: nzip site rm <target> [--yes]");46 return { kind: "rm", target: first };47 case "revert":48 if (second !== undefined) fail("usage: nzip site revert <target> [--to N] [--list]");49 return { kind: "revert", target: first };50 default:51 return fail(`unknown site command: ${action}`);52 }53}5455export async function cmdSiteGroup(56 config: Config,57 rest: string[],58 options: {59 ttl?: string;60 password?: string;61 noPassword: boolean;62 newSite: boolean;63 overwrite: boolean;64 yes: boolean;65 toSeq?: number;66 list: boolean;67 },68): Promise<void> {69 const invocation = parseSiteInvocation(rest);70 switch (invocation.kind) {71 case "push":72 return await cmdPush(73 config,74 invocation.source,75 invocation.target,76 options.ttl,77 options.password,78 options.noPassword,79 options.newSite,80 );81 case "cp":82 return await cmdCp(config, invocation.target, invocation.dir, options.overwrite);83 case "show":84 return await cmdSiteShow(config, invocation.target);85 case "policy":86 return await cmdSitePolicy(87 config,88 invocation.target,89 options.ttl,90 options.password,91 options.noPassword,92 );93 case "ls":94 return await cmdLs(config, invocation.vault);95 case "where":96 return await cmdWhere(config, invocation.target);97 case "rm":98 return await cmdRm(config, invocation.target, options.yes);99 case "revert":100 return await cmdRevert(config, invocation.target, options.toSeq, options.list);101 }102}