From bc663b13d38d9204340d85dd016f48c8121fad0a Mon Sep 17 00:00:00 2001 From: qti3e Date: Thu, 5 Feb 2026 00:10:52 -0800 Subject: [PATCH] feat: cache subcommand --- cache.ts | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ main.ts | 2 ++ 2 files changed, 53 insertions(+) create mode 100644 cache.ts diff --git a/cache.ts b/cache.ts new file mode 100644 index 0000000..0558db8 --- /dev/null +++ b/cache.ts @@ -0,0 +1,51 @@ +import { Command } from "@cliffy/command"; +import { green } from "@std/fmt/colors"; +import { getAppFromConfig, readConfig } from "./config.ts"; +import { withApp } from "./util.ts"; +import { createTrpcClient } from "./auth.ts"; +import type { GlobalOptions } from "./main.ts"; + +type CacheCommandContext = GlobalOptions & { + org?: string; + app?: string; +}; + +export const cacheInvalidateCommand = new Command() + .description("Invalidate cache tags for an application") + .arguments("") + .action(async (options, ...tags) => { + const configContent = await readConfig(Deno.cwd(), options.config); + let { org, app } = getAppFromConfig(configContent); + org ??= options.org; + app ??= options.app; + + const orgAndApp = await withApp( + options.debug, + options.endpoint, + false, + org, + app, + ); + + const trpcClient = createTrpcClient(options.debug, options.endpoint); + + // deno-lint-ignore no-explicit-any + await (trpcClient.apps as any).invalidateCache.mutate({ + org: orgAndApp.org, + app: orgAndApp.app, + tags, + }); + + console.log( + `${green("✓")} Cache invalidated for tags: ${tags.join(", ")}`, + ); + }); + +export const cacheCommand = new Command() + .description("Manage application cache") + .globalOption("--org ", "The name of the organization") + .globalOption("--app ", "The name of the application") + .action(() => { + cacheCommand.showHelp(); + }) + .command("invalidate", cacheInvalidateCommand); diff --git a/main.ts b/main.ts index 2978ada..e6d1bb3 100644 --- a/main.ts +++ b/main.ts @@ -16,6 +16,7 @@ import { import { createTrpcClient, getAuth } from "./auth.ts"; import token_storage from "./token_storage.ts"; import { sandboxCommand } from "./sandbox/mod.ts"; +import { cacheCommand } from "./cache.ts"; const MINIMUM_DENO_VERSION = "2.4.2"; if ( @@ -366,6 +367,7 @@ deploy your local directory to the specified application.`) ) .command("create", createCommand) .command("env", envCommand) + .command("cache", cacheCommand) .command("sandbox", sandboxCommand) .command("logs", logsCommand) .command("setup-aws", setupAWSCommand)