Skip to content

Commit

Permalink
Display error message when unknown command is provided to the wrangle…
Browse files Browse the repository at this point in the history
…r CLI
  • Loading branch information
petebacondarwin committed Dec 16, 2021
1 parent 4931f54 commit 6fc4c50
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 26 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-crabs-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

Display error message when unknown command is provided to the wrangler CLI.
88 changes: 63 additions & 25 deletions packages/wrangler/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,69 @@ function tap() {
}

describe("wrangler", () => {
it("should run", async () => {
const { stdout } = await w(undefined, { tap: true });

expect(stdout).toMatchInlineSnapshot(`
"wrangler
Commands:
wrangler init [name] 📥 Create a wrangler.toml configuration file
wrangler dev <filename> 👂 Start a local server for developing your worker
wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
wrangler tail [name] 🦚 Starts a log tailing session for a deployed Worker.
wrangler secret 🤫 Generate a secret that can be referenced in the worker script
wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
wrangler pages ⚡️ Configure Cloudflare Pages
Flags:
-c, --config Path to .toml configuration file [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Options:
-l, --local Run on my machine [boolean] [default: false]"
`);
describe("no command", () => {
it("should display a list of available commands", async () => {
const { stdout, stderr } = await w(undefined, { tap: true });

expect(stdout).toMatchInlineSnapshot(`
"wrangler
Commands:
wrangler init [name] 📥 Create a wrangler.toml configuration file
wrangler dev <filename> 👂 Start a local server for developing your worker
wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
wrangler tail [name] 🦚 Starts a log tailing session for a deployed Worker.
wrangler secret 🤫 Generate a secret that can be referenced in the worker script
wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
wrangler pages ⚡️ Configure Cloudflare Pages
Flags:
-c, --config Path to .toml configuration file [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Options:
-l, --local Run on my machine [boolean] [default: false]"
`);

expect(stderr).toEqual("");
});
});

describe("invalid command", () => {
it("should display an error", async () => {
const { stdout, stderr } = await w("invalid-command", { tap: true });

expect(stdout).toMatchInlineSnapshot(`
"wrangler
Commands:
wrangler init [name] 📥 Create a wrangler.toml configuration file
wrangler dev <filename> 👂 Start a local server for developing your worker
wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
wrangler tail [name] 🦚 Starts a log tailing session for a deployed Worker.
wrangler secret 🤫 Generate a secret that can be referenced in the worker script
wrangler kv:namespace 🗂️ Interact with your Workers KV Namespaces
wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
wrangler pages ⚡️ Configure Cloudflare Pages
Flags:
-c, --config Path to .toml configuration file [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Options:
-l, --local Run on my machine [boolean] [default: false]"
`);

expect(stderr).toMatchInlineSnapshot(`
"
Unknown command: invalid-command."
`);
});
});

describe("init", () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/wrangler/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,11 @@ export async function main(argv: string[]): Promise<void> {
["*"],
false,
() => {},
() => {
(args) => {
yargs.showHelp("log");
if (args._.length > 0) {
console.error(`\nUnknown command: ${args._}.`);
}
}
)
.scriptName("wrangler")
Expand Down

0 comments on commit 6fc4c50

Please sign in to comment.