clone

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

main
nzip / cli / commands / site.ts
site.ts 4.1K
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, cmdSiteFeedback, 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: "feedback"; target?: string }14 | { kind: "ls"; vault?: string }15 | { kind: "where"; target?: string }16 | { kind: "rm"; target?: string }17 | { kind: "revert"; target?: string };1819export function parseSiteInvocation(rest: string[]): SiteInvocation {20 const [action, first, second, ...extra] = rest;21 if (!action) {22 fail("usage: nzip site <push|cp|show|policy|feedback|ls|where|rm|revert> ...");23 }24 if (extra.length > 0) fail(`too many arguments for nzip site ${action}`);25 switch (action) {26 case "push":27 return { kind: "push", source: first, target: second };28 case "cp":29 return { kind: "cp", target: first, dir: second };30 case "show":31 if (second !== undefined) fail("usage: nzip site show <target>");32 return { kind: "show", target: first };33 case "policy":34 if (second !== undefined) fail("usage: nzip site policy <target> [options]");35 return { kind: "policy", target: first };36 case "feedback":37 if (second !== undefined) {38 fail("usage: nzip site feedback <target> [--request [--message TEXT] [--callback URL]]");39 }40 return { kind: "feedback", target: first };41 case "update":42 return fail(43 "site update was replaced by site policy",44 "publish content with `nzip site push <dir|file> <target>`; change TTL/password with `nzip site policy <target> ...`",45 );46 case "ls":47 if (second !== undefined) fail("usage: nzip site ls [vault]");48 return { kind: "ls", vault: first };49 case "where":50 if (second !== undefined) fail("usage: nzip site where <target>");51 return { kind: "where", target: first };52 case "rm":53 if (second !== undefined) fail("usage: nzip site rm <target> [--yes]");54 return { kind: "rm", target: first };55 case "revert":56 if (second !== undefined) fail("usage: nzip site revert <target> [--to N] [--list]");57 return { kind: "revert", target: first };58 default:59 return fail(`unknown site command: ${action}`);60 }61}6263export async function cmdSiteGroup(64 config: Config,65 rest: string[],66 options: {67 ttl?: string;68 password?: string;69 noPassword: boolean;70 newSite: boolean;71 overwrite: boolean;72 yes: boolean;73 toSeq?: number;74 list: boolean;75 feedback?: boolean;76 request: boolean;77 message?: string;78 callback?: string;79 },80): Promise<void> {81 const invocation = parseSiteInvocation(rest);82 switch (invocation.kind) {83 case "push":84 return await cmdPush(85 config,86 invocation.source,87 invocation.target,88 options.ttl,89 options.password,90 options.noPassword,91 options.newSite,92 undefined,93 options.feedback,94 );95 case "cp":96 return await cmdCp(config, invocation.target, invocation.dir, options.overwrite);97 case "show":98 return await cmdSiteShow(config, invocation.target);99 case "policy":100 return await cmdSitePolicy(101 config,102 invocation.target,103 options.ttl,104 options.password,105 options.noPassword,106 options.feedback,107 );108 case "feedback":109 return await cmdSiteFeedback(110 config,111 invocation.target,112 options.request,113 options.message,114 options.callback,115 );116 case "ls":117 return await cmdLs(config, invocation.vault);118 case "where":119 return await cmdWhere(config, invocation.target);120 case "rm":121 return await cmdRm(config, invocation.target, options.yes);122 case "revert":123 return await cmdRevert(config, invocation.target, options.toSeq, options.list);124 }125}