-
Notifications
You must be signed in to change notification settings - Fork 925
[wrangler] Add --json flag to r2 bucket info command #9530
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 4cc8e51 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
Hello. Since I'm who issued #9433, I'm very happy about this. Although it would be very preferable if it was possible to remove the banner line when using |
Thanks so much for the feedback, @frankichiro — totally agree with you. I'll go ahead and update the PR to suppress the banner when --json is used, so the output is clean and parseable. |
Made the requested changes to suppress the banner when --json is used. Let me know if there's anything else I should address — happy to iterate further. Thanks again for the guidance! |
Just wanted to follow up on this! Let me know if there’s anything else needed from my side to move this forward — happy to make any changes if required. Thanks again for your time! |
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
wrangler
commit: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, thanks so much for the contribution - sorry this was missed for a while, looks like our github automations went wonky and it wasn't added to our queue 😅
Just a couple of small things, but on the whole looks good.
Would you also be able to add a changeset? https://github.com/cloudflare/workers-sdk/blob/main/packages/wrangler/CONTRIBUTING.md#changesets
And if you're up to it, would you also be able to create a PR to the docs to add it to the wrangler command documentation? https://developers.cloudflare.com/workers/wrangler/commands/#r2-bucket-info
Let me know if you have any questions about this :)
packages/wrangler/src/r2/bucket.ts
Outdated
type: "boolean", | ||
default: false, | ||
}, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can hide the banner like this:
behaviour: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback , I’ve now reverted teh changes to wrangler-banner.ts. Instead, I’m using the behaviour: { showBanner: false } option inside the relevant CLI command for the --json path, similar to how it's done in d1/list.ts.
import { requireAuth } from "../../user"; | ||
import { getR2Bucket, getR2BucketMetrics } from "../../r2/helpers"; | ||
|
||
// Mock the dependencies |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add vi.unmock("../wrangler-banner");
to test the banner isn't included? we mock it out by default in tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added vi.unmock("../wrangler-banner") to ensure we’re explicitly testing that the banner isn’t printed when using --json.
it("should output valid JSON format when --json flag is used", async () => { | ||
let capturedOutput = ""; | ||
|
||
const originalConsoleLog = console.log; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should use the mockConsoleMethods()
helper here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated! I’m now using mockConsoleMethods() in the test instead of manually mocking console.log
also, it looks like you have some linting issues. you can run |
1064cfc
to
4cc8e51
Compare
4cc8e51
to
c7ddab9
Compare
Thanks a lot for the detailed review, -Used behaviour: { showBanner: false } instead of editing the banner file Let me know if i made a mistake anywhere. |
Just a quick note: I ended up cleaning up the commit history because the original one had some unrelated files accidentally committed. To keep things clean and focused, I created a fresh branch from main, reapplied only the relevant changes, and force-pushed — which unfortunately removed previous commit-level context. But I’ve addressed all the feedback again in this clean version. Once you’ve had a chance to review this updated commit, I’ll go ahead and create a follow-up PR to update the Wrangler documentation for the r2 bucket info command as well. Let me know if anything else is needed! |
What
Adds a
--json
flag to thewrangler r2 bucket info
command, returning the bucket info in clean JSON format.Why
Fixes #9433 — The current output is not machine-readable. Adding this makes the output usable in scripts and consistent with D1 commands that already support
--json
.How
--json
flag tor2 bucket info
--json
is passedTest Plan
pnpm exec vitest run packages/wrangler/src/__tests__/r2/bucket.test.ts
passedNotes
Currently, the banner line (
⛅ wrangler 4.18.0
) still appears even when using--json
.I left it in earlier to avoid blocking the main feature, but it has now been suppressed when
--json
is passed for cleaner machine-readable output.Example
With
--json
:Without --json:
$ wrangler r2 bucket info my-bucket-name (⛅️ wrangler 4.18.0\n──────────────────) Bucket Name: my-bucket-name Created At: 2025-06-07T15:55:22.222Z Location: APAC Storage Class: Standard Object Count: 0 Size: 0 B
Edit (June 12, 2025)
Implemented the requested change to suppress the banner (⛅ wrangler 4.18.0) when --json is used.