import { log } from "@clack/prompts" import { defineCommand } from "../lib/command" import { globalOptions, globalOptionsSchema } from "../lib/global-options" import z from "zod" import { apiClient } from "../lib/api-client" import { output, PROJECT_OPT, projectOptsSchema, sessionIntro, useProject, requireSession, PROJECT_OPTION_DESCRIPTIONS, } from "../utils" import { accent, dimmed } from "../lib/io" import { clearSpinner, startSpinner } from "../lib/spinner" export const projectShowCommand = defineCommand({ name: "show", description: "Show project details", options: { ...globalOptions, ...PROJECT_OPT, }, optionDescriptions: { ...PROJECT_OPTION_DESCRIPTIONS, }, schema: globalOptionsSchema.extend(projectOptsSchema.shape), run: showProject, }) /** * Displays details for a resolved project. * * @param opts - Validated options selecting the project. */ export async function showProject(opts: z.infer) { const session = await requireSession() output.normal(() => sessionIntro(session)) const { id: projectId } = await useProject(opts, { mode: "select" }) startSpinner("Fetching details") const full = await apiClient.project.get({ projectId }) clearSpinner() output .normal(() => log.message( [ `${accent(full.name)} ${dimmed(full.id)}`, ` Organization: ${full.org.name} ${dimmed(full.org.id)}`, ` Created: ${new Date(full.createdAt).toLocaleDateString()}`, ` Automations: ${full.activeAutomations.length}`, ...full.activeAutomations.flatMap((automation) => [ ` ${automation.description}`, ` ${dimmed(automation.identityKey)}`, ]), ].join("\n"), ), ) .json(full) }