Skip to content

Commit

Permalink
refactor to use defineCommand util
Browse files Browse the repository at this point in the history
  • Loading branch information
RamIdeas committed Oct 18, 2024
1 parent 1ad3b9a commit 4bb9f9b
Show file tree
Hide file tree
Showing 13 changed files with 402 additions and 455 deletions.
2 changes: 2 additions & 0 deletions packages/wrangler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
"blake3-wasm": "^2.1.5",
"chokidar": "^3.5.3",
"date-fns": "^4.1.0",
"esbuild": "0.17.19",
"itty-time": "^1.0.6",
"miniflare": "workspace:*",
"nanoid": "^3.3.3",
"path-to-regexp": "^6.3.0",
Expand Down
1 change: 1 addition & 0 deletions packages/wrangler/src/core/teams.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export type Teams =
| "Product: AI"
| "Product: Hyperdrive"
| "Product: Vectorize"
| "Product: Workflows"
| "Product: Cloudchamber";
5 changes: 0 additions & 5 deletions packages/wrangler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,11 +614,6 @@ export function createCLIParser(argv: string[]) {
return pipelines(pipelinesYargs.command(subHelp));
});

// workflows
wrangler.command("workflows", "🧑‍🍳 Manage Workflows", (workflowArgs) => {
return workflows(workflowArgs.command(subHelp), subHelp);
});

/******************** CMD GROUP ***********************/
// login
wrangler.command(
Expand Down
50 changes: 25 additions & 25 deletions packages/wrangler/src/workflows/commands/delete.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import { fetchResult } from "../../cfetch";
import { readConfig } from "../../config";
import { defineCommand } from "../../core";
import { logger } from "../../logger";
import { printWranglerBanner } from "../../update-check";
import { requireAuth } from "../../user";
import type {
CommonYargsArgv,
StrictYargsOptionsToInterface,
} from "../../yargs-types";

export const workflowDeleteOptions = (args: CommonYargsArgv) => {
return args.positional("name", {
describe: "Name of the workflow",
type: "string",
demandOption: true,
});
};
defineCommand({
command: "wrangler workflows delete",
metadata: {
description:
"Delete workflow - when deleting a workflow, it will also delete it's own instances",
owner: "Product: Workflows",
status: "open-beta",
},

type HandlerOptions = StrictYargsOptionsToInterface<
typeof workflowDeleteOptions
>;
export const workflowDeleteHandler = async (args: HandlerOptions) => {
await printWranglerBanner();
args: {
name: {
describe: "Name of the workflow",
type: "string",
demandOption: true,
},
},
positionalArgs: ["name"],

const config = readConfig(args.config, args);
const accountId = await requireAuth(config);
async handler(args, { config }) {
const accountId = await requireAuth(config);

await fetchResult(`/accounts/${accountId}/workflows/${args.name}`, {
method: "DELETE",
});
await fetchResult(`/accounts/${accountId}/workflows/${args.name}`, {
method: "DELETE",
});

logger.info(`Workflow "${args.name}" was successfully removed`);
};
logger.info(`Workflow "${args.name}" was successfully removed`);
},
});
95 changes: 46 additions & 49 deletions packages/wrangler/src/workflows/commands/describe.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,59 @@
import { logRaw } from "@cloudflare/cli";
import { white } from "@cloudflare/cli/colors";
import { fetchResult } from "../../cfetch";
import { readConfig } from "../../config";
import { printWranglerBanner } from "../../update-check";
import { defineCommand } from "../../core";
import { requireAuth } from "../../user";
import formatLabelledValues from "../../utils/render-labelled-values";
import {
type CommonYargsArgv,
type StrictYargsOptionsToInterface,
} from "../../yargs-types";
import type { Version, Workflow } from "../types";

export const workflowDescribeOptions = (args: CommonYargsArgv) => {
return args.positional("name", {
describe: "Name of the workflow",
type: "string",
demandOption: true,
});
};
defineCommand({
command: "wrangler workflows describe",
metadata: {
description: "Describe Workflow resource",
owner: "Product: Workflows",
status: "open-beta",
},
args: {
name: {
describe: "Name of the workflow",
type: "string",
demandOption: true,
},
},
positionalArgs: ["name"],
async handler(args, { config }) {
const accountId = await requireAuth(config);

type HandlerOptions = StrictYargsOptionsToInterface<
typeof workflowDescribeOptions
>;
export const workflowDescribeHandler = async (args: HandlerOptions) => {
await printWranglerBanner();
const workflow = await fetchResult<Workflow>(
`/accounts/${accountId}/workflows/${args.name}`
);

const config = readConfig(args.config, args);
const accountId = await requireAuth(config);
const versions = await fetchResult<Version[]>(
`/accounts/${accountId}/workflows/${args.name}/versions`
);

const workflow = await fetchResult<Workflow>(
`/accounts/${accountId}/workflows/${args.name}`
);
const latestVersion = versions[0];

const versions = await fetchResult<Version[]>(
`/accounts/${accountId}/workflows/${args.name}/versions`
);

const latestVersion = versions[0];

logRaw(
formatLabelledValues({
Name: workflow.name,
Id: workflow.id,
"Script Name": workflow.script_name,
"Class Name": workflow.class_name,
"Created On": workflow.created_on,
"Modified On": workflow.modified_on,
})
);
logRaw(white("Latest Version:"));
logRaw(
formatLabelledValues(
{
Id: latestVersion.id,
logRaw(
formatLabelledValues({
Name: workflow.name,
Id: workflow.id,
"Script Name": workflow.script_name,
"Class Name": workflow.class_name,
"Created On": workflow.created_on,
"Modified On": workflow.modified_on,
},
{ indentationCount: 2 }
)
);
};
})
);
logRaw(white("Latest Version:"));
logRaw(
formatLabelledValues(
{
Id: latestVersion.id,
"Created On": workflow.created_on,
"Modified On": workflow.modified_on,
},
{ indentationCount: 2 }
)
);
},
});
Loading

0 comments on commit 4bb9f9b

Please sign in to comment.