Skip to content

Commit 6dd1e23

Browse files
CarmenPopoviciupi0
andauthored
feat(wrangler): support --cwd cli argument (#8253)
This commit adds the `--cwd` global argument to the `wrangler` CLI to allow changing the current working directory before running any command. Co-authored-by: Pooya Parsa <pooya@pi0.io>
1 parent a9a4c33 commit 6dd1e23

32 files changed

+141
-14
lines changed

.changeset/khaki-years-act.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
Add `--cwd` global argument to the `wrangler` CLI to allow changing the current working directory before running any command.

packages/wrangler/src/__tests__/ai.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ describe("ai help", () => {
2727
2828
GLOBAL FLAGS
2929
-c, --config Path to Wrangler configuration file [string]
30+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
3031
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
3132
-h, --help Show help [boolean]
3233
-v, --version Show version number [boolean]"
@@ -55,6 +56,7 @@ describe("ai help", () => {
5556
5657
GLOBAL FLAGS
5758
-c, --config Path to Wrangler configuration file [string]
59+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
5860
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
5961
-h, --help Show help [boolean]
6062
-v, --version Show version number [boolean]"

packages/wrangler/src/__tests__/cert.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ describe("wrangler", () => {
440440
441441
GLOBAL FLAGS
442442
-c, --config Path to Wrangler configuration file [string]
443+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
443444
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
444445
-h, --help Show help [boolean]
445446
-v, --version Show version number [boolean]"

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

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ describe("cloudchamber create", () => {
8787
8888
GLOBAL FLAGS
8989
-c, --config Path to Wrangler configuration file [string]
90+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
9091
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
9192
-h, --help Show help [boolean]
9293
-v, --version Show version number [boolean]

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

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ describe("cloudchamber curl", () => {
4040
4141
GLOBAL FLAGS
4242
-c, --config Path to Wrangler configuration file [string]
43+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
4344
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
4445
-h, --help Show help [boolean]
4546
-v, --version Show version number [boolean]

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

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ describe("cloudchamber delete", () => {
3636
3737
GLOBAL FLAGS
3838
-c, --config Path to Wrangler configuration file [string]
39+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
3940
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
4041
-h, --help Show help [boolean]
4142
-v, --version Show version number [boolean]

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

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ describe("cloudchamber image", () => {
3737
3838
GLOBAL FLAGS
3939
-c, --config Path to Wrangler configuration file [string]
40+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
4041
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
4142
-h, --help Show help [boolean]
4243
-v, --version Show version number [boolean]

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

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ describe("cloudchamber list", () => {
3737
3838
GLOBAL FLAGS
3939
-c, --config Path to Wrangler configuration file [string]
40+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
4041
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
4142
-h, --help Show help [boolean]
4243
-v, --version Show version number [boolean]

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

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ describe("cloudchamber modify", () => {
7272
7373
GLOBAL FLAGS
7474
-c, --config Path to Wrangler configuration file [string]
75+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
7576
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
7677
-h, --help Show help [boolean]
7778
-v, --version Show version number [boolean]

packages/wrangler/src/__tests__/d1/d1.test.ts

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ describe("d1", () => {
3030
3131
GLOBAL FLAGS
3232
-c, --config Path to Wrangler configuration file [string]
33+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
3334
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
3435
-h, --help Show help [boolean]
3536
-v, --version Show version number [boolean]"
@@ -66,6 +67,7 @@ describe("d1", () => {
6667
6768
GLOBAL FLAGS
6869
-c, --config Path to Wrangler configuration file [string]
70+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
6971
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
7072
-h, --help Show help [boolean]
7173
-v, --version Show version number [boolean]"
@@ -95,6 +97,7 @@ describe("d1", () => {
9597
9698
GLOBAL FLAGS
9799
-c, --config Path to Wrangler configuration file [string]
100+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
98101
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
99102
-h, --help Show help [boolean]
100103
-v, --version Show version number [boolean]"
@@ -123,6 +126,7 @@ describe("d1", () => {
123126
124127
GLOBAL FLAGS
125128
-c, --config Path to Wrangler configuration file [string]
129+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
126130
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
127131
-h, --help Show help [boolean]
128132
-v, --version Show version number [boolean]"

packages/wrangler/src/__tests__/deployments.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ describe("deployments", () => {
6666
6767
GLOBAL FLAGS
6868
-c, --config Path to Wrangler configuration file [string]
69+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
6970
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
7071
-h, --help Show help [boolean]
7172
-v, --version Show version number [boolean]"

packages/wrangler/src/__tests__/docs.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ describe("wrangler docs", () => {
5858
5959
GLOBAL FLAGS
6060
-c, --config Path to Wrangler configuration file [string]
61+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
6162
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
6263
-h, --help Show help [boolean]
6364
-v, --version Show version number [boolean]

packages/wrangler/src/__tests__/hyperdrive.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ describe("hyperdrive help", () => {
3838
3939
GLOBAL FLAGS
4040
-c, --config Path to Wrangler configuration file [string]
41+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
4142
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
4243
-h, --help Show help [boolean]
4344
-v, --version Show version number [boolean]"
@@ -69,6 +70,7 @@ describe("hyperdrive help", () => {
6970
7071
GLOBAL FLAGS
7172
-c, --config Path to Wrangler configuration file [string]
73+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
7274
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
7375
-h, --help Show help [boolean]
7476
-v, --version Show version number [boolean]"

packages/wrangler/src/__tests__/index.test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ describe("wrangler", () => {
6969
7070
GLOBAL FLAGS
7171
-c, --config Path to Wrangler configuration file [string]
72+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
7273
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
7374
-h, --help Show help [boolean]
7475
-v, --version Show version number [boolean]
@@ -126,6 +127,7 @@ describe("wrangler", () => {
126127
127128
GLOBAL FLAGS
128129
-c, --config Path to Wrangler configuration file [string]
130+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
129131
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
130132
-h, --help Show help [boolean]
131133
-v, --version Show version number [boolean]
@@ -154,6 +156,14 @@ describe("wrangler", () => {
154156
`[Error: The argument "--config" expects a single value, but received multiple: ["wrangler.toml","example"].]`
155157
);
156158
});
159+
160+
it("should change cwd with --cwd", async () => {
161+
const spy = vi.spyOn(process, "chdir").mockImplementation(() => {});
162+
await runWrangler("--cwd /path");
163+
expect(process.chdir).toHaveBeenCalledTimes(1);
164+
expect(process.chdir).toHaveBeenCalledWith("/path");
165+
spy.mockRestore();
166+
});
157167
});
158168

159169
describe("preview", () => {
@@ -192,6 +202,7 @@ describe("wrangler", () => {
192202
193203
GLOBAL FLAGS
194204
-c, --config Path to Wrangler configuration file [string]
205+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
195206
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
196207
-h, --help Show help [boolean]
197208
-v, --version Show version number [boolean]"
@@ -213,6 +224,7 @@ describe("wrangler", () => {
213224
214225
GLOBAL FLAGS
215226
-c, --config Path to Wrangler configuration file [string]
227+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
216228
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
217229
-h, --help Show help [boolean]
218230
-v, --version Show version number [boolean]"
@@ -235,6 +247,7 @@ describe("wrangler", () => {
235247
236248
GLOBAL FLAGS
237249
-c, --config Path to Wrangler configuration file [string]
250+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
238251
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
239252
-h, --help Show help [boolean]
240253
-v, --version Show version number [boolean]"
@@ -255,6 +268,7 @@ describe("wrangler", () => {
255268
256269
GLOBAL FLAGS
257270
-c, --config Path to Wrangler configuration file [string]
271+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
258272
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
259273
-h, --help Show help [boolean]
260274
-v, --version Show version number [boolean]"
@@ -275,6 +289,7 @@ describe("wrangler", () => {
275289
276290
GLOBAL FLAGS
277291
-c, --config Path to Wrangler configuration file [string]
292+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
278293
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
279294
-h, --help Show help [boolean]
280295
-v, --version Show version number [boolean]"

packages/wrangler/src/__tests__/kv.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ describe("wrangler", () => {
4848
4949
GLOBAL FLAGS
5050
-c, --config Path to Wrangler configuration file [string]
51+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
5152
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
5253
-h, --help Show help [boolean]
5354
-v, --version Show version number [boolean]"
@@ -69,6 +70,7 @@ describe("wrangler", () => {
6970
7071
GLOBAL FLAGS
7172
-c, --config Path to Wrangler configuration file [string]
73+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
7274
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
7375
-h, --help Show help [boolean]
7476
-v, --version Show version number [boolean]"
@@ -97,6 +99,7 @@ describe("wrangler", () => {
9799
98100
GLOBAL FLAGS
99101
-c, --config Path to Wrangler configuration file [string]
102+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
100103
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
101104
-h, --help Show help [boolean]
102105
-v, --version Show version number [boolean]"
@@ -141,6 +144,7 @@ describe("wrangler", () => {
141144
142145
GLOBAL FLAGS
143146
-c, --config Path to Wrangler configuration file [string]
147+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
144148
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
145149
-h, --help Show help [boolean]
146150
-v, --version Show version number [boolean]
@@ -172,6 +176,7 @@ describe("wrangler", () => {
172176
173177
GLOBAL FLAGS
174178
-c, --config Path to Wrangler configuration file [string]
179+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
175180
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
176181
-h, --help Show help [boolean]
177182
-v, --version Show version number [boolean]
@@ -623,6 +628,7 @@ describe("wrangler", () => {
623628
624629
GLOBAL FLAGS
625630
-c, --config Path to Wrangler configuration file [string]
631+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
626632
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
627633
-h, --help Show help [boolean]
628634
-v, --version Show version number [boolean]
@@ -664,6 +670,7 @@ describe("wrangler", () => {
664670
665671
GLOBAL FLAGS
666672
-c, --config Path to Wrangler configuration file [string]
673+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
667674
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
668675
-h, --help Show help [boolean]
669676
-v, --version Show version number [boolean]
@@ -705,6 +712,7 @@ describe("wrangler", () => {
705712
706713
GLOBAL FLAGS
707714
-c, --config Path to Wrangler configuration file [string]
715+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
708716
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
709717
-h, --help Show help [boolean]
710718
-v, --version Show version number [boolean]
@@ -746,6 +754,7 @@ describe("wrangler", () => {
746754
747755
GLOBAL FLAGS
748756
-c, --config Path to Wrangler configuration file [string]
757+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
749758
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
750759
-h, --help Show help [boolean]
751760
-v, --version Show version number [boolean]
@@ -787,6 +796,7 @@ describe("wrangler", () => {
787796
788797
GLOBAL FLAGS
789798
-c, --config Path to Wrangler configuration file [string]
799+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
790800
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
791801
-h, --help Show help [boolean]
792802
-v, --version Show version number [boolean]
@@ -1156,6 +1166,7 @@ describe("wrangler", () => {
11561166
11571167
GLOBAL FLAGS
11581168
-c, --config Path to Wrangler configuration file [string]
1169+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
11591170
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
11601171
-h, --help Show help [boolean]
11611172
-v, --version Show version number [boolean]
@@ -1192,6 +1203,7 @@ describe("wrangler", () => {
11921203
11931204
GLOBAL FLAGS
11941205
-c, --config Path to Wrangler configuration file [string]
1206+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
11951207
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
11961208
-h, --help Show help [boolean]
11971209
-v, --version Show version number [boolean]
@@ -1229,6 +1241,7 @@ describe("wrangler", () => {
12291241
12301242
GLOBAL FLAGS
12311243
-c, --config Path to Wrangler configuration file [string]
1244+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
12321245
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
12331246
-h, --help Show help [boolean]
12341247
-v, --version Show version number [boolean]
@@ -1800,6 +1813,7 @@ describe("wrangler", () => {
18001813
18011814
GLOBAL FLAGS
18021815
-c, --config Path to Wrangler configuration file [string]
1816+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
18031817
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
18041818
-h, --help Show help [boolean]
18051819
-v, --version Show version number [boolean]"
@@ -1820,6 +1834,7 @@ describe("wrangler", () => {
18201834
18211835
GLOBAL FLAGS
18221836
-c, --config Path to Wrangler configuration file [string]
1837+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
18231838
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
18241839
-h, --help Show help [boolean]
18251840
-v, --version Show version number [boolean]"
@@ -1838,6 +1853,7 @@ describe("wrangler", () => {
18381853
18391854
GLOBAL FLAGS
18401855
-c, --config Path to Wrangler configuration file [string]
1856+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
18411857
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
18421858
-h, --help Show help [boolean]
18431859
-v, --version Show version number [boolean]"

packages/wrangler/src/__tests__/mtls-certificates.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ describe("wrangler", () => {
366366
367367
GLOBAL FLAGS
368368
-c, --config Path to Wrangler configuration file [string]
369+
--cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
369370
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
370371
-h, --help Show help [boolean]
371372
-v, --version Show version number [boolean]"

0 commit comments

Comments
 (0)