|
| 1 | +import { logRaw } from "@cloudflare/cli"; |
| 2 | +import { white } from "@cloudflare/cli/colors"; |
| 3 | +import { fetchResult } from "../../cfetch"; |
| 4 | +import { defineCommand } from "../../core"; |
| 5 | +import { requireAuth } from "../../user"; |
| 6 | +import formatLabelledValues from "../../utils/render-labelled-values"; |
| 7 | +import type { Version, Workflow } from "../types"; |
| 8 | + |
| 9 | +defineCommand({ |
| 10 | + command: "wrangler workflows describe", |
| 11 | + metadata: { |
| 12 | + description: "Describe Workflow resource", |
| 13 | + owner: "Product: Workflows", |
| 14 | + status: "open-beta", |
| 15 | + }, |
| 16 | + args: { |
| 17 | + name: { |
| 18 | + describe: "Name of the workflow", |
| 19 | + type: "string", |
| 20 | + demandOption: true, |
| 21 | + }, |
| 22 | + }, |
| 23 | + positionalArgs: ["name"], |
| 24 | + async handler(args, { config }) { |
| 25 | + const accountId = await requireAuth(config); |
| 26 | + |
| 27 | + const workflow = await fetchResult<Workflow>( |
| 28 | + `/accounts/${accountId}/workflows/${args.name}` |
| 29 | + ); |
| 30 | + |
| 31 | + const versions = await fetchResult<Version[]>( |
| 32 | + `/accounts/${accountId}/workflows/${args.name}/versions` |
| 33 | + ); |
| 34 | + |
| 35 | + const latestVersion = versions[0]; |
| 36 | + |
| 37 | + logRaw( |
| 38 | + formatLabelledValues({ |
| 39 | + Name: workflow.name, |
| 40 | + Id: workflow.id, |
| 41 | + "Script Name": workflow.script_name, |
| 42 | + "Class Name": workflow.class_name, |
| 43 | + "Created On": workflow.created_on, |
| 44 | + "Modified On": workflow.modified_on, |
| 45 | + }) |
| 46 | + ); |
| 47 | + logRaw(white("Latest Version:")); |
| 48 | + logRaw( |
| 49 | + formatLabelledValues( |
| 50 | + { |
| 51 | + Id: latestVersion.id, |
| 52 | + "Created On": workflow.created_on, |
| 53 | + "Modified On": workflow.modified_on, |
| 54 | + }, |
| 55 | + { indentationCount: 2 } |
| 56 | + ) |
| 57 | + ); |
| 58 | + }, |
| 59 | +}); |
0 commit comments