Skip to content

Commit

Permalink
chore: convert versions and versions secret to createCommand
Browse files Browse the repository at this point in the history
remove comment
  • Loading branch information
andyjessop committed Dec 4, 2024
1 parent a068672 commit f679597
Show file tree
Hide file tree
Showing 17 changed files with 1,048 additions and 1,136 deletions.
87 changes: 27 additions & 60 deletions packages/wrangler/src/__tests__/versions/versions.deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
parseVersionSpecs,
summariseVersionTraffic,
validateTrafficSubtotal,
versionsDeployOptions,
} from "../../versions/deploy";
import { collectCLIOutput } from "../helpers/collect-cli-output";
import { mockAccountId, mockApiToken } from "../helpers/mock-account-id";
Expand All @@ -30,7 +29,7 @@ import { runInTempDir } from "../helpers/run-in-tmp";
import { runWrangler } from "../helpers/run-wrangler";
import { writeWorkerSource } from "../helpers/write-worker-source";
import { writeWranglerConfig } from "../helpers/write-wrangler-config";
import type { VersionsDeployArgs } from "../../versions/deploy";
import type { ParseVersionSpecsArgs } from "../../versions/deploy";

Check failure on line 32 in packages/wrangler/src/__tests__/versions/versions.deploy.test.ts

View workflow job for this annotation

GitHub Actions / Checks

'ParseVersionSpecsArgs' is defined but never used. Allowed unused vars must match /^_/u

Check failure on line 32 in packages/wrangler/src/__tests__/versions/versions.deploy.test.ts

View workflow job for this annotation

GitHub Actions / Checks

'ParseVersionSpecsArgs' is defined but never used

describe("versions deploy", () => {
mockAccountId();
Expand Down Expand Up @@ -925,39 +924,28 @@ describe("versions deploy", () => {

describe("units", () => {
describe("parseVersionSpecs", () => {
const options = yargs().command(
"versions deploy [version-specs..]",
"",
// @ts-expect-error creating the command using a fresh yargs() but it expects one preconfigured with global options
versionsDeployOptions,
() => {}
);

test("no args", () => {
const input = "versions deploy";

const args = options.parse(input) as VersionsDeployArgs;
const result = parseVersionSpecs(args);
const result = parseVersionSpecs({});

expect(result).toMatchObject(new Map());
});

test("1 positional arg", () => {
const input = "versions deploy 10000000-0000-0000-0000-000000000000@10%";

const args = options.parse(input) as VersionsDeployArgs;
const result = parseVersionSpecs(args);
const result = parseVersionSpecs({
versionSpecs: ["10000000-0000-0000-0000-000000000000@10%"],
});

expect(Object.fromEntries(result)).toMatchObject({
"10000000-0000-0000-0000-000000000000": 10,
});
});
test("2 positional args", () => {
const input =
"versions deploy 10000000-0000-0000-0000-000000000000@10% 20000000-0000-0000-0000-000000000000@90%";

const args = options.parse(input) as VersionsDeployArgs;
const result = parseVersionSpecs(args);
const result = parseVersionSpecs({
versionSpecs: [
"10000000-0000-0000-0000-000000000000@10%",
"20000000-0000-0000-0000-000000000000@90%",
],
});

expect(Object.fromEntries(result)).toMatchObject({
"10000000-0000-0000-0000-000000000000": 10,
Expand All @@ -966,58 +954,37 @@ describe("units", () => {
});

test("1 pair of named args", () => {
const input =
"versions deploy --version-id 10000000-0000-0000-0000-000000000000 --percentage 10";

const args = options.parse(input) as VersionsDeployArgs;
const result = parseVersionSpecs(args);
const result = parseVersionSpecs({
percentage: [10],
versionId: ["10000000-0000-0000-0000-000000000000"],
});

expect(Object.fromEntries(result)).toMatchObject({
"10000000-0000-0000-0000-000000000000": 10,
});
});
test("2 pairs of named args", () => {
const input =
"versions deploy --version-id 10000000-0000-0000-0000-000000000000 --percentage 10 --version-id 20000000-0000-0000-0000-000000000000 --percentage 90";

const args = options.parse(input) as VersionsDeployArgs;
const result = parseVersionSpecs(args);

expect(Object.fromEntries(result)).toMatchObject({
"10000000-0000-0000-0000-000000000000": 10,
"20000000-0000-0000-0000-000000000000": 90,
const result = parseVersionSpecs({
percentage: [10, 90],
versionId: [
"10000000-0000-0000-0000-000000000000",
"20000000-0000-0000-0000-000000000000",
],
});
});
test("unordered named args", () => {
const input =
"versions deploy --version-id 10000000-0000-0000-0000-000000000000 --version-id 20000000-0000-0000-0000-000000000000 --percentage 10 --percentage 90";

const args = options.parse(input) as VersionsDeployArgs;
const result = parseVersionSpecs(args);

expect(Object.fromEntries(result)).toMatchObject({
"10000000-0000-0000-0000-000000000000": 10,
"20000000-0000-0000-0000-000000000000": 90,
});
});
test("unpaired named args", () => {
const input =
"versions deploy --version-id 10000000-0000-0000-0000-000000000000 --percentage 10 --version-id 20000000-0000-0000-0000-000000000000";

const args = options.parse(input) as VersionsDeployArgs;
const result = parseVersionSpecs(args);

expect(Object.fromEntries(result)).toMatchObject({
"10000000-0000-0000-0000-000000000000": 10,
"20000000-0000-0000-0000-000000000000": null,
const result = parseVersionSpecs({
percentage: [10],
versionId: [
"10000000-0000-0000-0000-000000000000",
"20000000-0000-0000-0000-000000000000",
],
});
});
test("unpaired, unordered named args", () => {
const input =
"versions deploy --version-id 10000000-0000-0000-0000-000000000000 --version-id 20000000-0000-0000-0000-000000000000 --percentage 10";

const args = options.parse(input) as VersionsDeployArgs;
const result = parseVersionSpecs(args);

expect(Object.fromEntries(result)).toMatchObject({
"10000000-0000-0000-0000-000000000000": 10,
Expand Down
48 changes: 24 additions & 24 deletions packages/wrangler/src/__tests__/versions/versions.help.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ describe("versions --help", () => {
🫧 List, view, upload and deploy Versions of your Worker to Cloudflare
COMMANDS
wrangler versions view <version-id> View the details of a specific version of your Worker [beta]
wrangler versions list List the 10 most recent Versions of your Worker [beta]
wrangler versions upload Uploads your Worker code and config as a new Version [beta]
wrangler versions deploy [version-specs..] Safely roll out new Versions of your Worker by splitting traffic between multiple Versions [beta]
wrangler versions view <version-id> View the details of a specific version of your Worker [open-beta]
wrangler versions list List the 10 most recent Versions of your Worker [open-beta]
wrangler versions upload Uploads your Worker code and config as a new Version [open-beta]
wrangler versions deploy [version-specs..] Safely roll out new Versions of your Worker by splitting traffic between multiple Versions [open-beta]
wrangler versions secret Generate a secret that can be referenced in a Worker
GLOBAL FLAGS
Expand All @@ -88,10 +88,10 @@ describe("versions --help", () => {
🫧 List, view, upload and deploy Versions of your Worker to Cloudflare
COMMANDS
wrangler versions view <version-id> View the details of a specific version of your Worker [beta]
wrangler versions list List the 10 most recent Versions of your Worker [beta]
wrangler versions upload Uploads your Worker code and config as a new Version [beta]
wrangler versions deploy [version-specs..] Safely roll out new Versions of your Worker by splitting traffic between multiple Versions [beta]
wrangler versions view <version-id> View the details of a specific version of your Worker [open-beta]
wrangler versions list List the 10 most recent Versions of your Worker [open-beta]
wrangler versions upload Uploads your Worker code and config as a new Version [open-beta]
wrangler versions deploy [version-specs..] Safely roll out new Versions of your Worker by splitting traffic between multiple Versions [open-beta]
wrangler versions secret Generate a secret that can be referenced in a Worker
GLOBAL FLAGS
Expand Down Expand Up @@ -126,10 +126,10 @@ describe("versions subhelp", () => {
🫧 List, view, upload and deploy Versions of your Worker to Cloudflare
COMMANDS
wrangler versions view <version-id> View the details of a specific version of your Worker [beta]
wrangler versions list List the 10 most recent Versions of your Worker [beta]
wrangler versions upload Uploads your Worker code and config as a new Version [beta]
wrangler versions deploy [version-specs..] Safely roll out new Versions of your Worker by splitting traffic between multiple Versions [beta]
wrangler versions view <version-id> View the details of a specific version of your Worker [open-beta]
wrangler versions list List the 10 most recent Versions of your Worker [open-beta]
wrangler versions upload Uploads your Worker code and config as a new Version [open-beta]
wrangler versions deploy [version-specs..] Safely roll out new Versions of your Worker by splitting traffic between multiple Versions [open-beta]
wrangler versions secret Generate a secret that can be referenced in a Worker
GLOBAL FLAGS
Expand All @@ -152,10 +152,10 @@ describe("versions subhelp", () => {
🫧 List, view, upload and deploy Versions of your Worker to Cloudflare
COMMANDS
wrangler versions view <version-id> View the details of a specific version of your Worker [beta]
wrangler versions list List the 10 most recent Versions of your Worker [beta]
wrangler versions upload Uploads your Worker code and config as a new Version [beta]
wrangler versions deploy [version-specs..] Safely roll out new Versions of your Worker by splitting traffic between multiple Versions [beta]
wrangler versions view <version-id> View the details of a specific version of your Worker [open-beta]
wrangler versions list List the 10 most recent Versions of your Worker [open-beta]
wrangler versions upload Uploads your Worker code and config as a new Version [open-beta]
wrangler versions deploy [version-specs..] Safely roll out new Versions of your Worker by splitting traffic between multiple Versions [open-beta]
wrangler versions secret Generate a secret that can be referenced in a Worker
GLOBAL FLAGS
Expand All @@ -178,10 +178,10 @@ describe("versions subhelp", () => {
🫧 List, view, upload and deploy Versions of your Worker to Cloudflare
COMMANDS
wrangler versions view <version-id> View the details of a specific version of your Worker [beta]
wrangler versions list List the 10 most recent Versions of your Worker [beta]
wrangler versions upload Uploads your Worker code and config as a new Version [beta]
wrangler versions deploy [version-specs..] Safely roll out new Versions of your Worker by splitting traffic between multiple Versions [beta]
wrangler versions view <version-id> View the details of a specific version of your Worker [open-beta]
wrangler versions list List the 10 most recent Versions of your Worker [open-beta]
wrangler versions upload Uploads your Worker code and config as a new Version [open-beta]
wrangler versions deploy [version-specs..] Safely roll out new Versions of your Worker by splitting traffic between multiple Versions [open-beta]
wrangler versions secret Generate a secret that can be referenced in a Worker
GLOBAL FLAGS
Expand All @@ -204,10 +204,10 @@ describe("versions subhelp", () => {
🫧 List, view, upload and deploy Versions of your Worker to Cloudflare
COMMANDS
wrangler versions view <version-id> View the details of a specific version of your Worker [beta]
wrangler versions list List the 10 most recent Versions of your Worker [beta]
wrangler versions upload Uploads your Worker code and config as a new Version [beta]
wrangler versions deploy [version-specs..] Safely roll out new Versions of your Worker by splitting traffic between multiple Versions [beta]
wrangler versions view <version-id> View the details of a specific version of your Worker [open-beta]
wrangler versions list List the 10 most recent Versions of your Worker [open-beta]
wrangler versions upload Uploads your Worker code and config as a new Version [open-beta]
wrangler versions deploy [version-specs..] Safely roll out new Versions of your Worker by splitting traffic between multiple Versions [open-beta]
wrangler versions secret Generate a secret that can be referenced in a Worker
GLOBAL FLAGS
Expand Down
61 changes: 53 additions & 8 deletions packages/wrangler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,18 @@ import { loginCommand, logoutCommand, whoamiCommand } from "./user/commands";
import { whoami } from "./user/whoami";
import { debugLogFilepath } from "./utils/log-file";
import { vectorize } from "./vectorize/index";
import registerVersionsSubcommands from "./versions";
import { versionsNamespace } from "./versions";
import { versionsDeployCommand } from "./versions/deploy";
import registerVersionsDeploymentsSubcommands from "./versions/deployments";
import { versionsListCommand } from "./versions/list";
import registerVersionsRollbackCommand from "./versions/rollback";
import { versionsSecretNamespace } from "./versions/secrets";
import { versionsSecretBulkCommand } from "./versions/secrets/bulk";
import { versionsSecretDeleteCommand } from "./versions/secrets/delete";
import { versionsSecretsListCommand } from "./versions/secrets/list";
import { versionsSecretPutCommand } from "./versions/secrets/put";
import { versionsUploadCommand } from "./versions/upload";
import { versionsViewCommand } from "./versions/view";
import { workflowsInstanceNamespace, workflowsNamespace } from "./workflows";
import { workflowsDeleteCommand } from "./workflows/commands/delete";
import { workflowsDescribeCommand } from "./workflows/commands/describe";
Expand Down Expand Up @@ -546,13 +555,49 @@ export function createCLIParser(argv: string[]) {

// versions
if (experimentalGradualRollouts) {
wrangler.command(
"versions",
"🫧 List, view, upload and deploy Versions of your Worker to Cloudflare",
(yargs) => {
return registerVersionsSubcommands(yargs.command(subHelp), subHelp);
}
);
registry.define([
{
command: "wrangler versions",
definition: versionsNamespace,
},
{
command: "wrangler versions view",
definition: versionsViewCommand,
},
{
command: "wrangler versions list",
definition: versionsListCommand,
},
{
command: "wrangler versions upload",
definition: versionsUploadCommand,
},
{
command: "wrangler versions deploy",
definition: versionsDeployCommand,
},
{
command: "wrangler versions secret",
definition: versionsSecretNamespace,
},
{
command: "wrangler versions secret put",
definition: versionsSecretPutCommand,
},
{
command: "wrangler versions secret bulk",
definition: versionsSecretBulkCommand,
},
{
command: "wrangler versions secret delete",
definition: versionsSecretDeleteCommand,
},
{
command: "wrangler versions secret list",
definition: versionsSecretsListCommand,
},
]);
registry.registerNamespace("versions");
}

// triggers
Expand Down
Loading

0 comments on commit f679597

Please sign in to comment.