From 6fc4c505f40500bdd8d46cbcd7f7372b04399ef0 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Wed, 15 Dec 2021 14:49:35 +0000 Subject: [PATCH] Display error message when unknown command is provided to the wrangler CLI --- .changeset/real-crabs-roll.md | 5 ++ packages/wrangler/src/__tests__/index.test.ts | 88 +++++++++++++------ packages/wrangler/src/index.tsx | 5 +- 3 files changed, 72 insertions(+), 26 deletions(-) create mode 100644 .changeset/real-crabs-roll.md diff --git a/.changeset/real-crabs-roll.md b/.changeset/real-crabs-roll.md new file mode 100644 index 000000000000..938dabf3d214 --- /dev/null +++ b/.changeset/real-crabs-roll.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +Display error message when unknown command is provided to the wrangler CLI. diff --git a/packages/wrangler/src/__tests__/index.test.ts b/packages/wrangler/src/__tests__/index.test.ts index 4d2e140f511c..4eca411c89e2 100644 --- a/packages/wrangler/src/__tests__/index.test.ts +++ b/packages/wrangler/src/__tests__/index.test.ts @@ -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 👂 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 👂 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 👂 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", () => { diff --git a/packages/wrangler/src/index.tsx b/packages/wrangler/src/index.tsx index 302312e6671f..ab752598d43c 100644 --- a/packages/wrangler/src/index.tsx +++ b/packages/wrangler/src/index.tsx @@ -134,8 +134,11 @@ export async function main(argv: string[]): Promise { ["*"], false, () => {}, - () => { + (args) => { yargs.showHelp("log"); + if (args._.length > 0) { + console.error(`\nUnknown command: ${args._}.`); + } } ) .scriptName("wrangler")