Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions cache.ts
Original file line number Diff line number Diff line change
@@ -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<CacheCommandContext>()
.description("Invalidate cache tags for an application")
.arguments("<tags...:string>")
.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<GlobalOptions>()
.description("Manage application cache")
.globalOption("--org <name:string>", "The name of the organization")
.globalOption("--app <name:string>", "The name of the application")
.action(() => {
cacheCommand.showHelp();
})
.command("invalidate", cacheInvalidateCommand);
2 changes: 2 additions & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
Expand Down
Loading