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 { deploymentSessionIntro } from "../lib/deployment-lifecycle" import { accent, dimmed } from "../lib/io" import { clearSpinner, startSpinner } from "../lib/spinner" import { output } from "../utils" /** Options accepted by the deployment inspection command. */ const showDeploymentOptsSchema = globalOptionsSchema.extend({ positionals: z.tuple([z.string().min(1)]), }) export const deploymentShowCommand = defineCommand({ name: "show", description: "Show deployment status", options: { ...globalOptions, }, positionals: [ { name: "deploymentId", description: "Deployment ID", required: true, }, ], schema: globalOptionsSchema.extend(showDeploymentOptsSchema.shape), run: showDeployment, }) /** * Displays normalized deployment status and authorization requirements. * * @param opts - Deployment identity to inspect. */ export async function showDeployment( opts: z.infer, ) { await deploymentSessionIntro() const [deploymentId] = opts.positionals startSpinner("Fetching deployment") const deployment = await apiClient.deployment.get({ deploymentId, }) clearSpinner() output .normal(() => log.message( [ `${deployment.project.organization.name} › ${accent(deployment.project.name)} ${dimmed(deployment.project.id)}`, ` Deployment: ${accent(deployment.id)}`, ` Status: ${deployment.status}`, ` Created: ${new Date(deployment.createdAt).toLocaleString()}`, ` Automations: ${deployment.automations.length}`, ...(deployment.failure ? [` Failure: ${deployment.failure.message}`] : []), ...(deployment.authorization ? [ ` Authorization: ${deployment.authorization.url}`, ...deployment.authorization.requirements.map( ({ binding, satisfied, serviceId }) => ` ${satisfied ? "Ready" : "Required"} ${serviceId}/${binding}`, ), ] : []), ].join("\n"), ), ) .json(deployment) }