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
`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
  • Loading branch information
CarmenPopoviciu committed May 13, 2024
1 parent 8d25839 commit 0075091
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 12 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.
28 changes: 26 additions & 2 deletions packages/wrangler/src/__tests__/pages/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,46 @@ describe("pages deploy", () => {
`);
});

it("should throw an error if no `[<directory>]` arg is specified in the `pages deploy` command", async () => {
it("should error if no `[<directory>]` arg is specified in the `pages deploy` command", async () => {
await expect(
runWrangler("pages deploy")
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Must specify a directory of assets to deploy. Please specify the [<directory>] argument in the \`pages deploy\` command, or configure \`pages_build_output_dir\` in your \`wrangler.toml\` configuration file."`
);
});

it("should throw an error if no `[--project-name]` is specified", async () => {
it("should error if no `[--project-name]` is specified", async () => {
await expect(
runWrangler("pages deploy public")
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Must specify a project name."`
);
});

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 @@ -31,4 +31,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"`
);
});
});
3 changes: 0 additions & 3 deletions packages/wrangler/src/__tests__/pages/pages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ 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]"
`);
Expand Down
11 changes: 4 additions & 7 deletions packages/wrangler/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,6 @@ export function createCLIParser(argv: string[]) {
// new flag -- shorthand
argv.includes("--x-versions");

const isPagesCmd = argv[0] === 'pages' ? true : false;

// Type check result against CommonYargsOptions to make sure we've included
// all common options
const wrangler: CommonYargsArgv = makeCLI(argv)
Expand All @@ -213,34 +211,29 @@ export function createCLIParser(argv: string[]) {
describe: "Show version number",
alias: "version",
type: "boolean",
global: !isPagesCmd,
})
.option("config", {
alias: "c",
describe: "Path to .toml configuration file",
type: "string",
requiresArg: true,
global: !isPagesCmd,
})
.option("env", {
alias: "e",
describe: "Environment to use for operations and .env files",
type: "string",
requiresArg: true,
global: !isPagesCmd,
})
.option("experimental-json-config", {
alias: "j",
describe: `Experimental: Support wrangler.json`,
type: "boolean",
global: !isPagesCmd,
})
.option("experimental-versions", {
describe: `Experimental: Support Worker Versions`,
type: "boolean",
hidden: true,
alias: ["x-versions", "experimental-gradual-rollouts"],
global: !isPagesCmd,
})
.check((args) => {
// Update logger level, before we do any logging
Expand Down Expand Up @@ -437,6 +430,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 @@ -93,6 +93,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 imperatively targeting a particular environment",
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 imperatively targeting a particular environment",
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 0075091

Please sign in to comment.