Skip to content

Commit bc663b1

Browse files
committed
feat: cache subcommand
1 parent 79290d5 commit bc663b1

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

cache.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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);

main.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
import { createTrpcClient, getAuth } from "./auth.ts";
1717
import token_storage from "./token_storage.ts";
1818
import { sandboxCommand } from "./sandbox/mod.ts";
19+
import { cacheCommand } from "./cache.ts";
1920

2021
const MINIMUM_DENO_VERSION = "2.4.2";
2122
if (
@@ -366,6 +367,7 @@ deploy your local directory to the specified application.`)
366367
)
367368
.command("create", createCommand)
368369
.command("env", envCommand)
370+
.command("cache", cacheCommand)
369371
.command("sandbox", sandboxCommand)
370372
.command("logs", logsCommand)
371373
.command("setup-aws", setupAWSCommand)

0 commit comments

Comments
 (0)