Skip to content

Commit 4f1c154

Browse files
refactor(wrangler): convert containers and cloudchamber commands to createCommand
Migrate containers and cloudchamber CLI commands from the legacy yargs defineCommand approach to the new createCommand pattern. This aligns these commands with the updated telemetry handling where events are dispatched directly from command handlers rather than middleware.
1 parent 8d8956d commit 4f1c154

30 files changed

+1956
-726
lines changed

packages/wrangler/src/__tests__/cloudchamber/create.test.ts

Lines changed: 97 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,6 @@ import { runWrangler } from "../helpers/run-wrangler";
1313
import { mockAccount, setWranglerConfig } from "./utils";
1414
import type { SSHPublicKeyItem } from "@cloudflare/containers-shared";
1515

16-
const MOCK_DEPLOYMENTS_COMPLEX_RESPONSE = `
17-
"{
18-
\\"id\\": \\"1\\",
19-
\\"type\\": \\"default\\",
20-
\\"created_at\\": \\"123\\",
21-
\\"account_id\\": \\"123\\",
22-
\\"vcpu\\": 4,
23-
\\"memory\\": \\"400MB\\",
24-
\\"memory_mib\\": 400,
25-
\\"version\\": 1,
26-
\\"image\\": \\"hello\\",
27-
\\"location\\": {
28-
\\"name\\": \\"sfo06\\",
29-
\\"enabled\\": true
30-
},
31-
\\"network\\": {
32-
\\"mode\\": \\"public\\",
33-
\\"ipv4\\": \\"1.1.1.1\\"
34-
},
35-
\\"placements_ref\\": \\"http://ref\\",
36-
\\"node_group\\": \\"metal\\"
37-
}"
38-
`;
39-
4016
function mockDeploymentPost() {
4117
msw.use(
4218
http.post(
@@ -103,7 +79,7 @@ describe("cloudchamber create", () => {
10379
expect(std.out).toMatchInlineSnapshot(`
10480
"wrangler cloudchamber create
10581
106-
Create a new deployment
82+
Create a new deployment [alpha]
10783
10884
GLOBAL FLAGS
10985
-c, --config Path to Wrangler configuration file [string]
@@ -230,7 +206,32 @@ describe("cloudchamber create", () => {
230206
);
231207
// so testing the actual UI will be harder than expected
232208
// TODO: think better on how to test UI actions
233-
expect(std.out).toMatchInlineSnapshot(MOCK_DEPLOYMENTS_COMPLEX_RESPONSE);
209+
expect(std.out).toMatchInlineSnapshot(`
210+
"
211+
⛅️ wrangler x.x.x
212+
──────────────────
213+
{
214+
\\"id\\": \\"1\\",
215+
\\"type\\": \\"default\\",
216+
\\"created_at\\": \\"123\\",
217+
\\"account_id\\": \\"123\\",
218+
\\"vcpu\\": 4,
219+
\\"memory\\": \\"400MB\\",
220+
\\"memory_mib\\": 400,
221+
\\"version\\": 1,
222+
\\"image\\": \\"hello\\",
223+
\\"location\\": {
224+
\\"name\\": \\"sfo06\\",
225+
\\"enabled\\": true
226+
},
227+
\\"network\\": {
228+
\\"mode\\": \\"public\\",
229+
\\"ipv4\\": \\"1.1.1.1\\"
230+
},
231+
\\"placements_ref\\": \\"http://ref\\",
232+
\\"node_group\\": \\"metal\\"
233+
}"
234+
`);
234235
});
235236

236237
it("should create deployment with instance type (detects no interactivity)", async () => {
@@ -253,7 +254,12 @@ describe("cloudchamber create", () => {
253254
await runWrangler(
254255
"cloudchamber create --image hello:world --location sfo06 --var HELLO:WORLD --var YOU:CONQUERED --instance-type lite --ipv4 true"
255256
);
256-
expect(std.out).toMatchInlineSnapshot(`"{}"`);
257+
expect(std.out).toMatchInlineSnapshot(`
258+
"
259+
⛅️ wrangler x.x.x
260+
──────────────────
261+
{}"
262+
`);
257263
});
258264

259265
it("properly reads wrangler config", async () => {
@@ -274,7 +280,32 @@ describe("cloudchamber create", () => {
274280
await runWrangler(
275281
"cloudchamber create --var HELLO:WORLD --var YOU:CONQUERED"
276282
);
277-
expect(std.out).toMatchInlineSnapshot(MOCK_DEPLOYMENTS_COMPLEX_RESPONSE);
283+
expect(std.out).toMatchInlineSnapshot(`
284+
"
285+
⛅️ wrangler x.x.x
286+
──────────────────
287+
{
288+
\\"id\\": \\"1\\",
289+
\\"type\\": \\"default\\",
290+
\\"created_at\\": \\"123\\",
291+
\\"account_id\\": \\"123\\",
292+
\\"vcpu\\": 4,
293+
\\"memory\\": \\"400MB\\",
294+
\\"memory_mib\\": 400,
295+
\\"version\\": 1,
296+
\\"image\\": \\"hello\\",
297+
\\"location\\": {
298+
\\"name\\": \\"sfo06\\",
299+
\\"enabled\\": true
300+
},
301+
\\"network\\": {
302+
\\"mode\\": \\"public\\",
303+
\\"ipv4\\": \\"1.1.1.1\\"
304+
},
305+
\\"placements_ref\\": \\"http://ref\\",
306+
\\"node_group\\": \\"metal\\"
307+
}"
308+
`);
278309
expect(std.err).toMatchInlineSnapshot(`""`);
279310
});
280311

@@ -306,7 +337,12 @@ describe("cloudchamber create", () => {
306337
await runWrangler(
307338
"cloudchamber create --var HELLO:WORLD --var YOU:CONQUERED"
308339
);
309-
expect(std.out).toMatchInlineSnapshot(`"{}"`);
340+
expect(std.out).toMatchInlineSnapshot(`
341+
"
342+
⛅️ wrangler x.x.x
343+
──────────────────
344+
{}"
345+
`);
310346
expect(std.err).toMatchInlineSnapshot(`""`);
311347
});
312348

@@ -349,7 +385,32 @@ describe("cloudchamber create", () => {
349385
await runWrangler(
350386
"cloudchamber create --image hello:world --location sfo06 --var HELLO:WORLD --var YOU:CONQUERED --all-ssh-keys --ipv4"
351387
);
352-
expect(std.out).toMatchInlineSnapshot(MOCK_DEPLOYMENTS_COMPLEX_RESPONSE);
388+
expect(std.out).toMatchInlineSnapshot(`
389+
"
390+
⛅️ wrangler x.x.x
391+
──────────────────
392+
{
393+
\\"id\\": \\"1\\",
394+
\\"type\\": \\"default\\",
395+
\\"created_at\\": \\"123\\",
396+
\\"account_id\\": \\"123\\",
397+
\\"vcpu\\": 4,
398+
\\"memory\\": \\"400MB\\",
399+
\\"memory_mib\\": 400,
400+
\\"version\\": 1,
401+
\\"image\\": \\"hello\\",
402+
\\"location\\": {
403+
\\"name\\": \\"sfo06\\",
404+
\\"enabled\\": true
405+
},
406+
\\"network\\": {
407+
\\"mode\\": \\"public\\",
408+
\\"ipv4\\": \\"1.1.1.1\\"
409+
},
410+
\\"placements_ref\\": \\"http://ref\\",
411+
\\"node_group\\": \\"metal\\"
412+
}"
413+
`);
353414
});
354415

355416
it("can't create deployment due to lack of fields (json)", async () => {
@@ -364,8 +425,11 @@ describe("cloudchamber create", () => {
364425
// so testing the actual UI will be harder than expected
365426
// TODO: think better on how to test UI actions
366427
expect(std.out).toMatchInlineSnapshot(`
367-
"
368-
If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
369-
`);
428+
"
429+
⛅️ wrangler x.x.x
430+
──────────────────
431+
432+
If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
433+
`);
370434
});
371435
});

packages/wrangler/src/__tests__/cloudchamber/curl.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe("cloudchamber curl", () => {
3434
expect(helpStd.out).toMatchInlineSnapshot(`
3535
"wrangler cloudchamber curl <path>
3636
37-
Send a request to an arbitrary Cloudchamber endpoint
37+
Send a request to an arbitrary Cloudchamber endpoint [alpha]
3838
3939
POSITIONALS
4040
path [string] [required] [default: \\"/\\"]

packages/wrangler/src/__tests__/cloudchamber/delete.test.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ describe("cloudchamber delete", () => {
3030
expect(std.out).toMatchInlineSnapshot(`
3131
"wrangler cloudchamber delete [deploymentId]
3232
33-
Delete an existing deployment that is running in the Cloudflare edge
33+
Delete an existing deployment that is running in the Cloudflare edge [alpha]
3434
3535
POSITIONALS
36-
deploymentId deployment you want to delete [string]
36+
deploymentId Deployment you want to delete [string]
3737
3838
GLOBAL FLAGS
3939
-c, --config Path to Wrangler configuration file [string]
@@ -62,7 +62,10 @@ describe("cloudchamber delete", () => {
6262
// TODO: think better on how to test UI actions
6363
expect(std.out).toMatchInlineSnapshot(
6464
`
65-
"{
65+
"
66+
⛅️ wrangler x.x.x
67+
──────────────────
68+
{
6669
\\"id\\": \\"1\\",
6770
\\"type\\": \\"default\\",
6871
\\"created_at\\": \\"123\\",
@@ -98,8 +101,11 @@ describe("cloudchamber delete", () => {
98101
// so testing the actual UI will be harder than expected
99102
// TODO: think better on how to test UI actions
100103
expect(std.out).toMatchInlineSnapshot(`
101-
"
102-
If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
103-
`);
104+
"
105+
⛅️ wrangler x.x.x
106+
──────────────────
107+
108+
If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
109+
`);
104110
});
105111
});

packages/wrangler/src/__tests__/cloudchamber/images.test.ts

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,7 @@ describe("cloudchamber image", () => {
2929
expect(std.out).toMatchInlineSnapshot(`
3030
"wrangler cloudchamber registries
3131
32-
Configure registries via Cloudchamber
33-
34-
COMMANDS
35-
wrangler cloudchamber registries configure Configure Cloudchamber to pull from specific registries
36-
wrangler cloudchamber registries credentials [domain] get a temporary password for a specific domain
37-
wrangler cloudchamber registries remove [domain] removes the registry at the given domain
38-
wrangler cloudchamber registries list list registries configured for this account
32+
Configure registries via Cloudchamber [alpha]
3933
4034
GLOBAL FLAGS
4135
-c, --config Path to Wrangler configuration file [string]
@@ -73,10 +67,13 @@ describe("cloudchamber image", () => {
7367
// so testing the actual UI will be harder than expected
7468
// TODO: think better on how to test UI actions
7569
expect(std.out).toMatchInlineSnapshot(`
76-
"{
77-
\\"domain\\": \\"docker.io\\"
78-
}"
79-
`);
70+
"
71+
⛅️ wrangler x.x.x
72+
──────────────────
73+
{
74+
\\"domain\\": \\"docker.io\\"
75+
}"
76+
`);
8077
});
8178

8279
it("should create an image registry (no interactivity)", async () => {
@@ -100,7 +97,12 @@ describe("cloudchamber image", () => {
10097
expect(std.err).toMatchInlineSnapshot(`""`);
10198
// so testing the actual UI will be harder than expected
10299
// TODO: think better on how to test UI actions
103-
expect(std.out).toMatchInlineSnapshot(`"jwt"`);
100+
expect(std.out).toMatchInlineSnapshot(`
101+
"
102+
⛅️ wrangler x.x.x
103+
──────────────────
104+
jwt"
105+
`);
104106
});
105107

106108
it("should remove an image registry (no interactivity)", async () => {
@@ -118,7 +120,12 @@ describe("cloudchamber image", () => {
118120
);
119121
await runWrangler("cloudchamber registries remove docker.io");
120122
expect(std.err).toMatchInlineSnapshot(`""`);
121-
expect(std.out).toMatchInlineSnapshot(`"{}"`);
123+
expect(std.out).toMatchInlineSnapshot(`
124+
"
125+
⛅️ wrangler x.x.x
126+
──────────────────
127+
{}"
128+
`);
122129
});
123130

124131
it("should list registries (no interactivity)", async () => {
@@ -145,7 +152,10 @@ describe("cloudchamber image", () => {
145152
await runWrangler("cloudchamber registries list");
146153
expect(std.err).toMatchInlineSnapshot(`""`);
147154
expect(std.out).toMatchInlineSnapshot(`
148-
"[
155+
"
156+
⛅️ wrangler x.x.x
157+
──────────────────
158+
[
149159
{
150160
\\"public_key\\": \\"\\",
151161
\\"domain\\": \\"docker.io\\"
@@ -182,8 +192,6 @@ describe("cloudchamber image list", () => {
182192
expect(std.out).toMatchInlineSnapshot(`
183193
"wrangler cloudchamber images list
184194
185-
List images in the Cloudflare managed registry
186-
187195
GLOBAL FLAGS
188196
-c, --config Path to Wrangler configuration file [string]
189197
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
@@ -224,7 +232,10 @@ describe("cloudchamber image list", () => {
224232
await runWrangler("cloudchamber images list");
225233
expect(std.err).toMatchInlineSnapshot(`""`);
226234
expect(std.out).toMatchInlineSnapshot(`
227-
"REPOSITORY TAG
235+
"
236+
⛅️ wrangler x.x.x
237+
──────────────────
238+
REPOSITORY TAG
228239
one hundred
229240
one ten
230241
two thousand
@@ -260,7 +271,10 @@ describe("cloudchamber image list", () => {
260271
await runWrangler("cloudchamber images list --filter '^two$'");
261272
expect(std.err).toMatchInlineSnapshot(`""`);
262273
expect(std.out).toMatchInlineSnapshot(`
263-
"REPOSITORY TAG
274+
"
275+
⛅️ wrangler x.x.x
276+
──────────────────
277+
REPOSITORY TAG
264278
two thousand
265279
two twenty"
266280
`);
@@ -294,7 +308,10 @@ describe("cloudchamber image list", () => {
294308
await runWrangler("cloudchamber images list");
295309
expect(std.err).toMatchInlineSnapshot(`""`);
296310
expect(std.out).toMatchInlineSnapshot(`
297-
"REPOSITORY TAG
311+
"
312+
⛅️ wrangler x.x.x
313+
──────────────────
314+
REPOSITORY TAG
298315
one hundred
299316
one ten
300317
two thousand
@@ -330,7 +347,10 @@ describe("cloudchamber image list", () => {
330347
await runWrangler("cloudchamber images list --json");
331348
expect(std.err).toMatchInlineSnapshot(`""`);
332349
expect(std.out).toMatchInlineSnapshot(`
333-
"[
350+
"
351+
⛅️ wrangler x.x.x
352+
──────────────────
353+
[
334354
{
335355
\\"name\\": \\"one\\",
336356
\\"tags\\": [
@@ -384,7 +404,10 @@ describe("cloudchamber image list", () => {
384404
await runWrangler("cloudchamber images list --json");
385405
expect(std.err).toMatchInlineSnapshot(`""`);
386406
expect(std.out).toMatchInlineSnapshot(`
387-
"[
407+
"
408+
⛅️ wrangler x.x.x
409+
──────────────────
410+
[
388411
{
389412
\\"name\\": \\"one\\",
390413
\\"tags\\": [
@@ -434,8 +457,6 @@ describe("cloudchamber image delete", () => {
434457
expect(std.out).toMatchInlineSnapshot(`
435458
"wrangler cloudchamber images delete <image>
436459
437-
Remove an image from the Cloudflare managed registry
438-
439460
POSITIONALS
440461
image Image and tag to delete, of the form IMAGE:TAG [string] [required]
441462
@@ -488,7 +509,12 @@ describe("cloudchamber image delete", () => {
488509
await runWrangler("cloudchamber images delete one:hundred");
489510
expect(std.err).toMatchInlineSnapshot(`""`);
490511
expect(std.out).toMatchInlineSnapshot(
491-
`"Deleted one:hundred (some-digest)"`
512+
`
513+
"
514+
⛅️ wrangler x.x.x
515+
──────────────────
516+
Deleted one:hundred (some-digest)"
517+
`
492518
);
493519
});
494520

0 commit comments

Comments
 (0)