Skip to content

Commit

Permalink
fix(wrangler): Display correct global flags in wrangler pages --help (
Browse files Browse the repository at this point in the history
#5814)

`wrangler pages --help` currently displays a list of global
flags that are not all supported by Pages, such as `--env`,
`--config`, and `--experimental-json-config`.

This commit ensure that only flags that apply to Pages are
listed when running `--help`.

Fixes #5725

Co-authored-by: Carmen Popoviciu <cpopoviciu@cloudflare.com>
  • Loading branch information
CarmenPopoviciu and Carmen Popoviciu committed May 15, 2024
1 parent 82415b5 commit 2869e03
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 9 deletions.
19 changes: 19 additions & 0 deletions .changeset/quiet-wolves-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
"wrangler": minor
---

fix: Display correct global flags in `wrangler pages --help`

Running `wrangler pages --help` will list, amongst others, the following global flags:

```
-j, --experimental-json-config
-c, --config
-e, --env
-h, --help
-v, --version
```

This is not accurate, since flags such as `--config`, `--experimental-json-config`, or `env` are not supported by Pages.

This commit ensures we display the correct global flags that apply to Pages.
30 changes: 26 additions & 4 deletions packages/wrangler/src/__tests__/pages/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ describe("pages deploy", () => {
directory The directory of static files to upload [string]
Flags:
-j, --experimental-json-config Experimental: Support wrangler.json [boolean]
-e, --env Environment to use for operations and .env files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Options:
--project-name The name of the project you want to deploy to [string]
Expand Down Expand Up @@ -90,6 +88,30 @@ describe("pages deploy", () => {
);
});

it("should error if the [--config] command line arg was specififed", async () => {
await expect(
runWrangler("pages deploy public --config=/path/to/wrangler.toml")
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Pages does not support custom paths for the \`wrangler.toml\` configuration file"`
);
});

it("should error if the [--experimental-json-config] command line arg was specififed", async () => {
await expect(
runWrangler("pages deploy public --experimental-json-config")
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Pages does not support \`wrangler.json\`"`
);
});

it("should error if the [--env] command line arg was specififed", async () => {
await expect(
runWrangler("pages deploy public --env=production")
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Pages does not support imperatively targeting a particular environment"`
);
});

it("should upload a directory of files", async () => {
writeFileSync("logo.png", "foobar");
mockGetUploadTokenRequest(
Expand Down
16 changes: 16 additions & 0 deletions packages/wrangler/src/__tests__/pages/dev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,20 @@ describe("pages dev", () => {
`"Pages does not support custom paths for the \`wrangler.toml\` configuration file"`
);
});

it("should error if the [--experimental-json-config] command line arg was specififed", async () => {
await expect(
runWrangler("pages dev public --experimental-json-config")
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Pages does not support \`wrangler.json\`"`
);
});

it("should error if the [--env] command line arg was specififed", async () => {
await expect(
runWrangler("pages dev public --env=production")
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Pages does not support imperatively targeting a particular environment"`
);
});
});
7 changes: 2 additions & 5 deletions packages/wrangler/src/__tests__/pages/pages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ describe("pages", () => {
wrangler pages download ⚡️ Download settings from your project
Flags:
-j, --experimental-json-config Experimental: Support wrangler.json [boolean]
-c, --config Path to .toml configuration file [string]
-e, --env Environment to use for operations and .env files [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]"
-h, --help Show help [boolean]
-v, --version Show version number [boolean]"
`);
});

Expand Down
4 changes: 4 additions & 0 deletions packages/wrangler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,10 @@ export function createCLIParser(argv: string[]) {

// pages
wrangler.command("pages", "⚡️ Configure Cloudflare Pages", (pagesYargs) => {
// Pages does not support the `--config`, `--experimental-json-config`,
// and `--env` flags, therefore hiding them from the global flags list.
pagesYargs.hide("config").hide("env").hide("experimental-json-config");

return pages(pagesYargs, subHelp);
});

Expand Down
11 changes: 11 additions & 0 deletions packages/wrangler/src/pages/deploy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ export const Handler = async (args: PagesDeployArgs) => {
);
}

if (args.experimentalJsonConfig) {
throw new FatalError("Pages does not support `wrangler.json`", 1);
}

if (args.env) {
throw new FatalError(
"Pages does not support targeting an environment with the --env flag. Use the --branch flag to target your production or preview branch",
1
);
}

let config: Config | undefined;
const configPath = findWranglerToml(process.cwd(), false);

Expand Down
11 changes: 11 additions & 0 deletions packages/wrangler/src/pages/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,17 @@ export const Handler = async (args: PagesDevArguments) => {
);
}

if (args.experimentalJsonConfig) {
throw new FatalError("Pages does not support `wrangler.json`", 1);
}

if (args.env) {
throw new FatalError(
"Pages does not support targeting an environment with the --env flag. Use the --branch flag to target your production or preview branch",
1
);
}

if (args.scriptPath !== undefined) {
logger.warn(
`\`--script-path\` is deprecated and will be removed in a future version of Wrangler.\nThe Worker script should be named \`_worker.js\` and located in the build output directory of your project (specified with \`wrangler pages dev <directory>\`).`
Expand Down

0 comments on commit 2869e03

Please sign in to comment.