Skip to content

Commit

Permalink
fix: display the correct help information when a subcommand is invalid (
Browse files Browse the repository at this point in the history
#1052)

Previously, when an invalid subcommand was used, such as `wrangler r2 foo`,
the help that was displayed showed the top-level commands prefixed by the command in used.
E.g.

```
wrangler r2 init [name]       📥 Create a wrangler.toml configuration file
wrangler r2 dev [script]      👂 Start a local server for developing your worker
wrangler r2 publish [script]  🆙 Publish your Worker to Cloudflare.
...
```

Now the correct command help is displayed:

```
$ wrangler r2 foo

✘ [ERROR] Unknown argument: foo

wrangler r2

📦 Interact with an R2 store

Commands:
  wrangler r2 bucket  Manage R2 buckets

Flags:
  -c, --config   Path to .toml configuration file  [string]
  -h, --help     Show help  [boolean]
  -v, --version  Show version number  [boolean]
```

Fixes #871
  • Loading branch information
petebacondarwin authored May 18, 2022
1 parent 6791703 commit 233eef2
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 121 deletions.
39 changes: 39 additions & 0 deletions .changeset/heavy-rabbits-accept.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
"wrangler": patch
---

fix: display the correct help information when a subcommand is invalid

Previously, when an invalid subcommand was used, such as `wrangler r2 foo`,
the help that was displayed showed the top-level commands prefixed by the command in used.
E.g.

```
wrangler r2 init [name] 📥 Create a wrangler.toml configuration file
wrangler r2 dev [script] 👂 Start a local server for developing your worker
wrangler r2 publish [script] 🆙 Publish your Worker to Cloudflare.
...
```

Now the correct command help is displayed:

```
$ wrangler r2 foo
✘ [ERROR] Unknown argument: foo
wrangler r2
📦 Interact with an R2 store
Commands:
wrangler r2 bucket Manage R2 buckets
Flags:
-c, --config Path to .toml configuration file [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
```

Fixes #871
13 changes: 6 additions & 7 deletions packages/wrangler/src/__tests__/dev.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,11 @@ describe("wrangler dev", () => {
expect(std).toMatchInlineSnapshot(`
Object {
"debug": "",
"err": "wrangler dev [script]
"err": "X [ERROR] Not enough arguments following: site
",
"out": "
wrangler dev [script]
👂 Start a local server for developing your worker
Expand Down Expand Up @@ -811,12 +815,7 @@ describe("wrangler dev", () => {
--minify Minify the script [boolean]
--node-compat Enable node.js compatibility [boolean]
--experimental-enable-local-persistence Enable persistence for this session (only for local mode) [boolean]
--inspect Enable dev tools [deprecated] [boolean]
X [ERROR] Not enough arguments following: site
",
"out": "
",
--inspect Enable dev tools [deprecated] [boolean]",
"warn": "",
}
`);
Expand Down
11 changes: 5 additions & 6 deletions packages/wrangler/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ describe("wrangler", () => {

expect(std.out).toMatchInlineSnapshot(`
"
"
`);
expect(std.err).toMatchInlineSnapshot(`
"wrangler
wrangler
Commands:
wrangler init [name] 📥 Create a wrangler.toml configuration file
Expand All @@ -86,8 +83,10 @@ describe("wrangler", () => {
Flags:
-c, --config Path to .toml configuration file [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
X [ERROR] Unknown argument: invalid-command
-v, --version Show version number [boolean]"
`);
expect(std.err).toMatchInlineSnapshot(`
"X [ERROR] Unknown argument: invalid-command
"
`);
Expand Down
137 changes: 56 additions & 81 deletions packages/wrangler/src/__tests__/kv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ describe("wrangler", () => {
);
expect(std.out).toMatchInlineSnapshot(`
"
"
`);
expect(std.err).toMatchInlineSnapshot(`
"wrangler kv:namespace create <namespace>
wrangler kv:namespace create <namespace>
Create a new namespace
Expand All @@ -65,8 +62,10 @@ describe("wrangler", () => {
Options:
-e, --env Perform on a specific environment [string]
--preview Interact with a preview namespace [boolean]
X [ERROR] Not enough non-option arguments: got 0, need at least 1
--preview Interact with a preview namespace [boolean]"
`);
expect(std.err).toMatchInlineSnapshot(`
"X [ERROR] Not enough non-option arguments: got 0, need at least 1
"
`);
Expand All @@ -80,10 +79,7 @@ describe("wrangler", () => {
);
expect(std.out).toMatchInlineSnapshot(`
"
"
`);
expect(std.err).toMatchInlineSnapshot(`
"wrangler kv:namespace create <namespace>
wrangler kv:namespace create <namespace>
Create a new namespace
Expand All @@ -97,8 +93,10 @@ describe("wrangler", () => {
Options:
-e, --env Perform on a specific environment [string]
--preview Interact with a preview namespace [boolean]
X [ERROR] Unknown arguments: def, ghi
--preview Interact with a preview namespace [boolean]"
`);
expect(std.err).toMatchInlineSnapshot(`
"X [ERROR] Unknown arguments: def, ghi
"
`);
Expand All @@ -113,10 +111,7 @@ describe("wrangler", () => {

expect(std.out).toMatchInlineSnapshot(`
"
"
`);
expect(std.err).toMatchInlineSnapshot(`
"wrangler kv:namespace create <namespace>
wrangler kv:namespace create <namespace>
Create a new namespace
Expand All @@ -130,8 +125,10 @@ describe("wrangler", () => {
Options:
-e, --env Perform on a specific environment [string]
--preview Interact with a preview namespace [boolean]
X [ERROR] The namespace binding name \\"abc-def\\" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number.
--preview Interact with a preview namespace [boolean]"
`);
expect(std.err).toMatchInlineSnapshot(`
"X [ERROR] The namespace binding name \\"abc-def\\" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number.
"
`);
Expand Down Expand Up @@ -283,21 +280,7 @@ describe("wrangler", () => {
A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."
`);
expect(std.err).toMatchInlineSnapshot(`
"wrangler kv:namespace delete
Deletes a given namespace.
Flags:
-c, --config Path to .toml configuration file [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Options:
--binding The name of the namespace to delete [string]
--namespace-id The id of the namespace to delete [string]
-e, --env Perform on a specific environment [string]
--preview Interact with a preview namespace [boolean]
X [ERROR] Not able to delete namespace.
"X [ERROR] Not able to delete namespace.
A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
Expand Down Expand Up @@ -489,10 +472,7 @@ describe("wrangler", () => {

expect(std.out).toMatchInlineSnapshot(`
"
"
`);
expect(std.err).toMatchInlineSnapshot(`
"wrangler kv:key put <key> [value]
wrangler kv:key put <key> [value]
Writes a single key/value pair to the given namespace.
Expand All @@ -512,8 +492,10 @@ describe("wrangler", () => {
--preview Interact with a preview namespace [boolean]
--ttl Time for which the entries should be visible [number]
--expiration Time since the UNIX epoch after which the entry expires [number]
--path Read value from the file at a given path [string]
X [ERROR] Not enough non-option arguments: got 0, need at least 1
--path Read value from the file at a given path [string]"
`);
expect(std.err).toMatchInlineSnapshot(`
"X [ERROR] Not enough non-option arguments: got 0, need at least 1
"
`);
Expand All @@ -528,10 +510,7 @@ describe("wrangler", () => {

expect(std.out).toMatchInlineSnapshot(`
"
"
`);
expect(std.err).toMatchInlineSnapshot(`
"wrangler kv:key put <key> [value]
wrangler kv:key put <key> [value]
Writes a single key/value pair to the given namespace.
Expand All @@ -551,8 +530,10 @@ describe("wrangler", () => {
--preview Interact with a preview namespace [boolean]
--ttl Time for which the entries should be visible [number]
--expiration Time since the UNIX epoch after which the entry expires [number]
--path Read value from the file at a given path [string]
X [ERROR] Exactly one of the arguments binding and namespace-id is required
--path Read value from the file at a given path [string]"
`);
expect(std.err).toMatchInlineSnapshot(`
"X [ERROR] Exactly one of the arguments binding and namespace-id is required
"
`);
Expand All @@ -567,10 +548,7 @@ describe("wrangler", () => {

expect(std.out).toMatchInlineSnapshot(`
"
"
`);
expect(std.err).toMatchInlineSnapshot(`
"wrangler kv:key put <key> [value]
wrangler kv:key put <key> [value]
Writes a single key/value pair to the given namespace.
Expand All @@ -590,8 +568,10 @@ describe("wrangler", () => {
--preview Interact with a preview namespace [boolean]
--ttl Time for which the entries should be visible [number]
--expiration Time since the UNIX epoch after which the entry expires [number]
--path Read value from the file at a given path [string]
X [ERROR] Arguments binding and namespace-id are mutually exclusive
--path Read value from the file at a given path [string]"
`);
expect(std.err).toMatchInlineSnapshot(`
"X [ERROR] Arguments binding and namespace-id are mutually exclusive
"
`);
Expand All @@ -606,10 +586,7 @@ describe("wrangler", () => {

expect(std.out).toMatchInlineSnapshot(`
"
"
`);
expect(std.err).toMatchInlineSnapshot(`
"wrangler kv:key put <key> [value]
wrangler kv:key put <key> [value]
Writes a single key/value pair to the given namespace.
Expand All @@ -629,8 +606,10 @@ describe("wrangler", () => {
--preview Interact with a preview namespace [boolean]
--ttl Time for which the entries should be visible [number]
--expiration Time since the UNIX epoch after which the entry expires [number]
--path Read value from the file at a given path [string]
X [ERROR] Exactly one of the arguments value and path is required
--path Read value from the file at a given path [string]"
`);
expect(std.err).toMatchInlineSnapshot(`
"X [ERROR] Exactly one of the arguments value and path is required
"
`);
Expand All @@ -645,10 +624,7 @@ describe("wrangler", () => {

expect(std.out).toMatchInlineSnapshot(`
"
"
`);
expect(std.err).toMatchInlineSnapshot(`
"wrangler kv:key put <key> [value]
wrangler kv:key put <key> [value]
Writes a single key/value pair to the given namespace.
Expand All @@ -668,8 +644,10 @@ describe("wrangler", () => {
--preview Interact with a preview namespace [boolean]
--ttl Time for which the entries should be visible [number]
--expiration Time since the UNIX epoch after which the entry expires [number]
--path Read value from the file at a given path [string]
X [ERROR] Arguments value and path are mutually exclusive
--path Read value from the file at a given path [string]"
`);
expect(std.err).toMatchInlineSnapshot(`
"X [ERROR] Arguments value and path are mutually exclusive
"
`);
Expand Down Expand Up @@ -965,10 +943,7 @@ describe("wrangler", () => {
);
expect(std.out).toMatchInlineSnapshot(`
"
"
`);
expect(std.err).toMatchInlineSnapshot(`
"wrangler kv:key get <key>
wrangler kv:key get <key>
Reads a single value by key from the given namespace.
Expand All @@ -984,8 +959,10 @@ describe("wrangler", () => {
--binding The name of the namespace to get from [string]
--namespace-id The id of the namespace to get from [string]
-e, --env Perform on a specific environment [string]
--preview Interact with a preview namespace [boolean] [default: false]
X [ERROR] Not enough non-option arguments: got 0, need at least 1
--preview Interact with a preview namespace [boolean] [default: false]"
`);
expect(std.err).toMatchInlineSnapshot(`
"X [ERROR] Not enough non-option arguments: got 0, need at least 1
"
`);
Expand All @@ -999,10 +976,7 @@ describe("wrangler", () => {
);
expect(std.out).toMatchInlineSnapshot(`
"
"
`);
expect(std.err).toMatchInlineSnapshot(`
"wrangler kv:key get <key>
wrangler kv:key get <key>
Reads a single value by key from the given namespace.
Expand All @@ -1018,8 +992,10 @@ describe("wrangler", () => {
--binding The name of the namespace to get from [string]
--namespace-id The id of the namespace to get from [string]
-e, --env Perform on a specific environment [string]
--preview Interact with a preview namespace [boolean] [default: false]
X [ERROR] Exactly one of the arguments binding and namespace-id is required
--preview Interact with a preview namespace [boolean] [default: false]"
`);
expect(std.err).toMatchInlineSnapshot(`
"X [ERROR] Exactly one of the arguments binding and namespace-id is required
"
`);
Expand All @@ -1034,10 +1010,7 @@ describe("wrangler", () => {

expect(std.out).toMatchInlineSnapshot(`
"
"
`);
expect(std.err).toMatchInlineSnapshot(`
"wrangler kv:key get <key>
wrangler kv:key get <key>
Reads a single value by key from the given namespace.
Expand All @@ -1053,8 +1026,10 @@ describe("wrangler", () => {
--binding The name of the namespace to get from [string]
--namespace-id The id of the namespace to get from [string]
-e, --env Perform on a specific environment [string]
--preview Interact with a preview namespace [boolean] [default: false]
X [ERROR] Arguments binding and namespace-id are mutually exclusive
--preview Interact with a preview namespace [boolean] [default: false]"
`);
expect(std.err).toMatchInlineSnapshot(`
"X [ERROR] Arguments binding and namespace-id are mutually exclusive
"
`);
Expand Down
Loading

0 comments on commit 233eef2

Please sign in to comment.