Skip to content

Commit 40c72d3

Browse files
committed
Support the WRANGLER_HIDE_BANNER environment variable across Wrangler & C3
1 parent 46ccf0e commit 40c72d3

File tree

10 files changed

+83
-12
lines changed

10 files changed

+83
-12
lines changed

.changeset/eager-pans-hang.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
"wrangler": minor
3+
---
4+
5+
When the `WRANGLER_HIDE_BANNER` environment variable is provided, Wrangler will no longer display a version banner. This applies to all commands.
6+
7+
For instance, previously running `wrangler docs` would give the following output:
8+
9+
```
10+
> wrangler docs
11+
⛅️ wrangler 4.47.0
12+
───────────────────
13+
Opening a link in your default browser: https://developers.cloudflare.com/workers/wrangler/commands/
14+
```
15+
16+
With `WRANGLER_HIDE_BANNER`, this is now:
17+
18+
```
19+
> WRANGLER_HIDE_BANNER=true wrangler docs
20+
Opening a link in your default browser: https://developers.cloudflare.com/workers/wrangler/commands/
21+
```

.changeset/funny-eggs-grow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-cloudflare": patch
3+
---
4+
5+
When `create-cloudflare` runs a Wrangler command (e.g. `wrangler deploy` if the user chooses to deploy during the project creation flow), it will now hide the Wrangler version banner.

packages/create-cloudflare/e2e/tests/cli/cli.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ describe("Create Cloudflare CLI", () => {
464464
);
465465
expect(normalizeOutput(output)).toMatchInlineSnapshot(`
466466
"create-cloudflare <version>
467-
The create-cloudflare cli (also known as C3) is a command-line tool designed to help you set up and deploy new applications to Cloudflare. In addition to speed, it leverages officially developed templates for Workers and framework-specific setup guides to ensure each new application that you set up follows Cloudflare and any third-party best practices for deployment on the Cloudflare network.
467+
The create-cloudflare CLI (also known as C3) is a command-line tool designed to help you set up and deploy new applications to Cloudflare. In addition to speed, it leverages officially developed templates for Workers and framework-specific setup guides to ensure each new application that you set up follows Cloudflare and any third-party best practices for deployment on the Cloudflare network.
468468
USAGE
469469
<USAGE>
470470
OPTIONS
@@ -536,7 +536,7 @@ describe("Create Cloudflare CLI", () => {
536536
const { output } = await runC3(["--help"], [], logStream);
537537
expect(normalizeOutput(output)).toMatchInlineSnapshot(`
538538
"create-cloudflare <version>
539-
The create-cloudflare cli (also known as C3) is a command-line tool designed to help you set up and deploy new applications to Cloudflare. In addition to speed, it leverages officially developed templates for Workers and framework-specific setup guides to ensure each new application that you set up follows Cloudflare and any third-party best practices for deployment on the Cloudflare network.
539+
The create-cloudflare CLI (also known as C3) is a command-line tool designed to help you set up and deploy new applications to Cloudflare. In addition to speed, it leverages officially developed templates for Workers and framework-specific setup guides to ensure each new application that you set up follows Cloudflare and any third-party best practices for deployment on the Cloudflare network.
540540
USAGE
541541
<USAGE>
542542
OPTIONS

packages/create-cloudflare/src/helpers/args.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export type ArgumentsDefinition = {
4444

4545
export const cliDefinition: ArgumentsDefinition = {
4646
intro: `
47-
The create-cloudflare cli (also known as C3) is a command-line tool designed to help you set up and deploy new applications to Cloudflare. In addition to speed, it leverages officially developed templates for Workers and framework-specific setup guides to ensure each new application that you set up follows Cloudflare and any third-party best practices for deployment on the Cloudflare network.
47+
The create-cloudflare CLI (also known as C3) is a command-line tool designed to help you set up and deploy new applications to Cloudflare. In addition to speed, it leverages officially developed templates for Workers and framework-specific setup guides to ensure each new application that you set up follows Cloudflare and any third-party best practices for deployment on the Cloudflare network.
4848
`,
4949
positionals: [
5050
{

packages/create-cloudflare/src/helpers/command.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,12 @@ export const runCommand = async (
5656
// Don't send metrics data on any wrangler commands if telemetry is disabled in C3
5757
// If telemetry is disabled separately for wrangler, wrangler will handle that
5858
if (args[0] === "wrangler") {
59+
opts.env ??= {};
5960
const metrics = readMetricsConfig();
6061
if (metrics.c3permission?.enabled === false) {
61-
opts.env ??= {};
6262
opts.env["WRANGLER_SEND_METRICS"] = "false";
6363
}
64+
opts.env["WRANGLER_HIDE_BANNER"] = "true";
6465
}
6566
const abortController = new AbortController();
6667
const cmd = spawn(executable, [...args], {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { mockConsoleMethods } from "./helpers/mock-console";
2+
import { useMockIsTTY } from "./helpers/mock-istty";
3+
import { runWrangler } from "./helpers/run-wrangler";
4+
5+
describe("wrangler banner", () => {
6+
const std = mockConsoleMethods();
7+
const { setIsTTY } = useMockIsTTY();
8+
beforeEach(() => {
9+
setIsTTY(true);
10+
});
11+
12+
it("should display the version banner by default", async () => {
13+
await runWrangler("--version");
14+
15+
expect(std.out).toMatchInlineSnapshot(`
16+
"
17+
⛅️ wrangler x.x.x
18+
──────────────────"
19+
`);
20+
});
21+
22+
it("should hide the version banner when WRANGLER_HIDE_BANNER is present", async () => {
23+
vi.stubEnv("WRANGLER_HIDE_BANNER", "true");
24+
await runWrangler("--version");
25+
26+
expect(std.out).toMatchInlineSnapshot(`""`);
27+
});
28+
});

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import chalk from "chalk";
77
import { fetchResult } from "../cfetch";
88
import { createCloudflareClient } from "../cfetch/internal";
99
import { readConfig } from "../config";
10+
import { getWranglerHideBanner } from "../environment-variables/misc-variables";
1011
import { hasDefinedEnvironments } from "../environments";
1112
import { run } from "../experimental-flags";
1213
import { logger } from "../logger";
@@ -107,7 +108,7 @@ function createHandler(def: CommandDefinition, commandName: string) {
107108
const shouldPrintBanner = def.behaviour?.printBanner;
108109

109110
if (
110-
/* No defautl behaviour override: show the banner */
111+
/* No default behaviour override: show the banner */
111112
shouldPrintBanner === undefined ||
112113
/* Explicit opt in: show the banner */
113114
(typeof shouldPrintBanner === "boolean" &&
@@ -119,14 +120,15 @@ function createHandler(def: CommandDefinition, commandName: string) {
119120
await printWranglerBanner();
120121
}
121122

122-
if (def.metadata.deprecated) {
123-
logger.warn(def.metadata.deprecatedMessage);
124-
}
125-
if (def.metadata.statusMessage) {
126-
logger.warn(def.metadata.statusMessage);
127-
}
123+
if (!getWranglerHideBanner()) {
124+
if (def.metadata.deprecated) {
125+
logger.warn(def.metadata.deprecatedMessage);
126+
}
128127

129-
// TODO(telemetry): send command started event
128+
if (def.metadata.statusMessage) {
129+
logger.warn(def.metadata.statusMessage);
130+
}
131+
}
130132

131133
await def.validateArgs?.(args);
132134

packages/wrangler/src/environment-variables/factory.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ type VariableNames =
5151
| "WRANGLER_LOG_SANITIZE"
5252
/** Directory for ND-JSON output files. */
5353
| "WRANGLER_OUTPUT_FILE_DIRECTORY"
54+
/** Hide the Wrangler version banner */
55+
| "WRANGLER_HIDE_BANNER"
5456

5557
// ## Build & Deployment Configuration
5658

packages/wrangler/src/environment-variables/misc-variables.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,11 @@ export const getDisableConfigWatching = getBooleanEnvironmentVariableFactory({
313313
variableName: "WRANGLER_CI_DISABLE_CONFIG_WATCHING",
314314
defaultValue: false,
315315
});
316+
317+
/**
318+
* Hide the Wrangler version banner and command status (deprecated/experimental) warnings
319+
*/
320+
export const getWranglerHideBanner = getBooleanEnvironmentVariableFactory({
321+
variableName: "WRANGLER_HIDE_BANNER",
322+
defaultValue: false,
323+
});

packages/wrangler/src/wrangler-banner.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import semiver from "semiver";
33
import stripAnsi from "strip-ansi";
44
import supportsColor from "supports-color";
55
import { version as wranglerVersion } from "../package.json";
6+
import { getWranglerHideBanner } from "./environment-variables/misc-variables";
67
import { logger } from "./logger";
78
import { updateCheck } from "./update-check";
89

@@ -13,6 +14,9 @@ const MIN_NODE_VERSION = "20.0.0";
1314
declare const WRANGLER_PRERELEASE_LABEL: string;
1415

1516
export async function printWranglerBanner(performUpdateCheck = true) {
17+
if (getWranglerHideBanner()) {
18+
return;
19+
}
1620
let text =
1721
typeof WRANGLER_PRERELEASE_LABEL === "undefined"
1822
? ` ⛅️ wrangler ${wranglerVersion}`

0 commit comments

Comments
 (0)