Skip to content

Commit

Permalink
feat(wrangler): support -C, --cwd cli argument
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 3, 2025
1 parent 59c7c8e commit 5a2e268
Show file tree
Hide file tree
Showing 33 changed files with 129 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/khaki-years-act.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": minor
---

Add `-C, --cwd` global argument to the `wrangler` CLI to allow changing the current working directory before running any command.
2 changes: 2 additions & 0 deletions packages/wrangler/src/__tests__/ai.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe("ai help", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]"
Expand Down Expand Up @@ -55,6 +56,7 @@ describe("ai help", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]"
Expand Down
1 change: 1 addition & 0 deletions packages/wrangler/src/__tests__/cert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ describe("wrangler", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ describe("cloudchamber create", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Expand Down
1 change: 1 addition & 0 deletions packages/wrangler/src/__tests__/cloudchamber/curl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ describe("cloudchamber curl", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ describe("cloudchamber delete", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe("cloudchamber image", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Expand Down
1 change: 1 addition & 0 deletions packages/wrangler/src/__tests__/cloudchamber/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe("cloudchamber list", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ describe("cloudchamber modify", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Expand Down
4 changes: 4 additions & 0 deletions packages/wrangler/src/__tests__/d1/d1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe("d1", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]"
Expand Down Expand Up @@ -66,6 +67,7 @@ describe("d1", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]"
Expand Down Expand Up @@ -95,6 +97,7 @@ describe("d1", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]"
Expand Down Expand Up @@ -123,6 +126,7 @@ describe("d1", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]"
Expand Down
1 change: 1 addition & 0 deletions packages/wrangler/src/__tests__/deployments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ describe("deployments", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]"
Expand Down
1 change: 1 addition & 0 deletions packages/wrangler/src/__tests__/dev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,7 @@ describe.sequential("wrangler dev", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Expand Down
1 change: 1 addition & 0 deletions packages/wrangler/src/__tests__/docs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe("wrangler docs", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Expand Down
2 changes: 2 additions & 0 deletions packages/wrangler/src/__tests__/hyperdrive.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe("hyperdrive help", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]"
Expand Down Expand Up @@ -69,6 +70,7 @@ describe("hyperdrive help", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]"
Expand Down
15 changes: 15 additions & 0 deletions packages/wrangler/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ describe("wrangler", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Expand Down Expand Up @@ -126,6 +127,7 @@ describe("wrangler", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Expand Down Expand Up @@ -154,6 +156,14 @@ describe("wrangler", () => {
`[Error: The argument "--config" expects a single value, but received multiple: ["wrangler.toml","example"].]`
);
});

it("should change cwd with -C, --cwd", async () => {
const spy = vi.spyOn(process, "chdir").mockImplementation(() => {});
await Promise.all([runWrangler("-C /path"), runWrangler("--cwd /path")]);
expect(process.chdir).toHaveBeenCalledTimes(2);
expect(process.chdir).toHaveBeenCalledWith("/path");
spy.mockRestore();
});
});

describe("preview", () => {
Expand Down Expand Up @@ -192,6 +202,7 @@ describe("wrangler", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]"
Expand All @@ -213,6 +224,7 @@ describe("wrangler", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]"
Expand All @@ -235,6 +247,7 @@ describe("wrangler", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]"
Expand All @@ -255,6 +268,7 @@ describe("wrangler", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]"
Expand All @@ -275,6 +289,7 @@ describe("wrangler", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]"
Expand Down
16 changes: 16 additions & 0 deletions packages/wrangler/src/__tests__/kv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ describe("wrangler", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]"
Expand All @@ -69,6 +70,7 @@ describe("wrangler", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]"
Expand Down Expand Up @@ -97,6 +99,7 @@ describe("wrangler", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]"
Expand Down Expand Up @@ -141,6 +144,7 @@ describe("wrangler", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Expand Down Expand Up @@ -172,6 +176,7 @@ describe("wrangler", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Expand Down Expand Up @@ -623,6 +628,7 @@ describe("wrangler", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Expand Down Expand Up @@ -664,6 +670,7 @@ describe("wrangler", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Expand Down Expand Up @@ -705,6 +712,7 @@ describe("wrangler", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Expand Down Expand Up @@ -746,6 +754,7 @@ describe("wrangler", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Expand Down Expand Up @@ -787,6 +796,7 @@ describe("wrangler", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Expand Down Expand Up @@ -1156,6 +1166,7 @@ describe("wrangler", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Expand Down Expand Up @@ -1192,6 +1203,7 @@ describe("wrangler", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Expand Down Expand Up @@ -1229,6 +1241,7 @@ describe("wrangler", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Expand Down Expand Up @@ -1800,6 +1813,7 @@ describe("wrangler", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]"
Expand All @@ -1820,6 +1834,7 @@ describe("wrangler", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]"
Expand All @@ -1838,6 +1853,7 @@ describe("wrangler", () => {
GLOBAL FLAGS
-c, --config Path to Wrangler configuration file [string]
-C, --cwd Run as if Wrangler was started in the specified directory instead of the current working directory [string]
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]"
Expand Down
Loading

0 comments on commit 5a2e268

Please sign in to comment.