Skip to content

Commit b0cee1d

Browse files
authored
[wrangler] fix: suppress status badge when printBanner returns false (#13837)
1 parent 2af4ce0 commit b0cee1d

3 files changed

Lines changed: 28 additions & 5 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Fix beta/open-beta status message ignoring `printBanner: false` — when a command sets `printBanner: (args) => !args.json`, the status banner no longer appears in JSON output

packages/wrangler/src/__tests__/ai-search.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,16 @@ describe("ai-search commands", () => {
236236
expect(parsed).toEqual([MOCK_INSTANCE]);
237237
});
238238

239+
it("should not print beta status banner when --json is passed", async ({
240+
expect,
241+
}) => {
242+
mockListInstances([MOCK_INSTANCE]);
243+
await runWrangler("ai-search list --json");
244+
// The beta/open-beta statusMessage must not appear in stderr when
245+
// printBanner returns false (i.e. when --json suppresses the banner).
246+
expect(std.warn).not.toContain("open beta");
247+
});
248+
239249
it("should output empty JSON array when no instances exist with --json", async ({
240250
expect,
241251
}) => {

packages/wrangler/src/core/register-yargs-command.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,29 @@ function createHandler(def: InternalCommandDefinition, argv: string[]) {
127127

128128
try {
129129
const shouldPrintBanner = def.behaviour?.printBanner ?? true;
130-
131-
if (
130+
const bannerEnabled =
132131
shouldPrintBanner === true ||
133132
(typeof shouldPrintBanner === "function" &&
134-
shouldPrintBanner(args) === true)
135-
) {
133+
shouldPrintBanner(args) === true);
134+
135+
if (bannerEnabled) {
136136
await printWranglerBanner();
137137
}
138138

139+
// Suppress statusMessage when printBanner is a dynamic function that
140+
// returned false (e.g. `--json` mode). When printBanner is the static
141+
// boolean `false`, we preserve existing behaviour and still show
142+
// status warnings — those commands opted out of the Wrangler banner,
143+
// not necessarily the status message.
144+
const statusMessageEnabled =
145+
typeof shouldPrintBanner !== "function" || bannerEnabled;
146+
139147
if (!getWranglerHideBanner()) {
140148
if (def.metadata.deprecated) {
141149
logger.warn(def.metadata.deprecatedMessage);
142150
}
143151

144-
if (def.metadata.statusMessage) {
152+
if (statusMessageEnabled && def.metadata.statusMessage) {
145153
logger.warn(def.metadata.statusMessage);
146154
}
147155
}

0 commit comments

Comments
 (0)