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 { clearSpinner, startSpinner } from "../lib/spinner" import { AUTOMATION_OPT, automationOptsSchema, output, PROJECT_OPT, requireSession, sessionIntro, useAutomation, PROJECT_OPTION_DESCRIPTIONS, AUTOMATION_OPTION_DESCRIPTIONS, } from "../utils" import { renderAutomationDetails } from "./automation-list" export const automationShowCommand = defineCommand({ name: "show", description: "Show automation details", options: { ...globalOptions, ...AUTOMATION_OPT, ...PROJECT_OPT, }, optionDescriptions: { ...AUTOMATION_OPTION_DESCRIPTIONS, ...PROJECT_OPTION_DESCRIPTIONS, }, schema: globalOptionsSchema.extend(automationOptsSchema.shape), run: showAutomation, }) /** * Displays one active automation's triggers and account bindings. * * @param opts - Automation and optional project selectors. */ export async function showAutomation( opts: z.infer, ) { const session = await requireSession("show an automation") output.normal(() => sessionIntro(session)) const selected = await useAutomation(opts) startSpinner("Fetching automation") const automation = await apiClient.automation.get({ automation: selected.id, }) clearSpinner() output .normal(() => log.message(renderAutomationDetails(automation))) .json(automation) }