|
| 1 | +import { Command } from "@cliffy/command"; |
| 2 | +import { green } from "@std/fmt/colors"; |
| 3 | +import { getAppFromConfig, readConfig } from "./config.ts"; |
| 4 | +import { withApp } from "./util.ts"; |
| 5 | +import { createTrpcClient } from "./auth.ts"; |
| 6 | +import type { GlobalOptions } from "./main.ts"; |
| 7 | + |
| 8 | +type CacheCommandContext = GlobalOptions & { |
| 9 | + org?: string; |
| 10 | + app?: string; |
| 11 | +}; |
| 12 | + |
| 13 | +export const cacheInvalidateCommand = new Command<CacheCommandContext>() |
| 14 | + .description("Invalidate cache tags for an application") |
| 15 | + .arguments("<tags...:string>") |
| 16 | + .action(async (options, ...tags) => { |
| 17 | + const configContent = await readConfig(Deno.cwd(), options.config); |
| 18 | + let { org, app } = getAppFromConfig(configContent); |
| 19 | + org ??= options.org; |
| 20 | + app ??= options.app; |
| 21 | + |
| 22 | + const orgAndApp = await withApp( |
| 23 | + options.debug, |
| 24 | + options.endpoint, |
| 25 | + false, |
| 26 | + org, |
| 27 | + app, |
| 28 | + ); |
| 29 | + |
| 30 | + const trpcClient = createTrpcClient(options.debug, options.endpoint); |
| 31 | + |
| 32 | + // deno-lint-ignore no-explicit-any |
| 33 | + await (trpcClient.apps as any).invalidateCache.mutate({ |
| 34 | + org: orgAndApp.org, |
| 35 | + app: orgAndApp.app, |
| 36 | + tags, |
| 37 | + }); |
| 38 | + |
| 39 | + console.log( |
| 40 | + `${green("✓")} Cache invalidated for tags: ${tags.join(", ")}`, |
| 41 | + ); |
| 42 | + }); |
| 43 | + |
| 44 | +export const cacheCommand = new Command<GlobalOptions>() |
| 45 | + .description("Manage application cache") |
| 46 | + .globalOption("--org <name:string>", "The name of the organization") |
| 47 | + .globalOption("--app <name:string>", "The name of the application") |
| 48 | + .action(() => { |
| 49 | + cacheCommand.showHelp(); |
| 50 | + }) |
| 51 | + .command("invalidate", cacheInvalidateCommand); |
0 commit comments