Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Conversation

petebacondarwin
Copy link
Contributor

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

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 cloudflare#871
@changeset-bot
Copy link

changeset-bot bot commented May 18, 2022

🦋 Changeset detected

Latest commit: 270dcc6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
wrangler Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@petebacondarwin
Copy link
Contributor Author

Note that a small change, as a result of this fix, is that the help string is now rendered on the stdout rather than stderr stream. The error message itself is still rendered on stderr.

@github-actions
Copy link
Contributor

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/runs/2345131982/npm-package-wrangler-1052

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/prs/1052/npm-package-wrangler-1052

Or you can use npx with this latest build directly:

npx https://prerelease-registry.developers.workers.dev/runs/2345131982/npm-package-wrangler-1052 dev path/to/script.js

@@ -17,6 +17,33 @@ describe("wrangler", () => {

describe("r2", () => {
describe("bucket", () => {
it("should show the correct help when an invalid command is passed", async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the new test that proves the fix.

Copy link
Contributor

@threepointone threepointone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever fix!

@petebacondarwin petebacondarwin merged commit 233eef2 into cloudflare:main May 18, 2022
@petebacondarwin petebacondarwin deleted the unknown-command-help-message-fix branch May 18, 2022 13:07
@github-actions github-actions bot mentioned this pull request May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 BUG: "r2" added incorrectly to help messages when using invalid r2 subcommands
2 participants