Skip to content

Commit

Permalink
allow disabling readConfig warning with defineCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
edmundhung committed Nov 4, 2024
1 parent 54d2163 commit ec6d4cd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
7 changes: 7 additions & 0 deletions packages/wrangler/src/core/define-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,20 @@ export type CommandDefinition<
* @default true
*/
printBanner?: boolean;

/**
* By default, wrangler will print warnings about wrangler.toml configuration.
* Set this value to `false` to skip printing these warnings.
*/
printConfigWarnings?: boolean;
};

/**
* A plain key-value object describing the CLI args for this command.
* Shared args can be defined as another plain object and spread into this.
*/
args?: NamedArgDefs;

/**
* Optionally declare some of the named args as positional args.
* The order of this array is the order they are expected in the command.
Expand Down
7 changes: 6 additions & 1 deletion packages/wrangler/src/core/register-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,12 @@ function createHandler(def: CommandDefinition) {
await def.validateArgs?.(args);

await def.handler(args, {
config: readConfig(args.config, args),
config: readConfig(
args.config,
args,
undefined,
!(def.behaviour?.printConfigWarnings ?? true)
),
errors: { UserError, FatalError },
logger,
fetchResult,
Expand Down
19 changes: 12 additions & 7 deletions packages/wrangler/src/user/commands.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { readConfig } from "../config";
import { defineCommand } from "../core/define-command";
import { CommandLineArgsError } from "../errors";
import * as metrics from "../metrics";
Expand All @@ -12,6 +11,9 @@ defineCommand({
owner: "Workers: Authoring and Testing",
status: "stable",
},
behaviour: {
printConfigWarnings: false,
},
args: {
"scopes-list": {
describe: "List all the available OAuth scopes with descriptions",
Expand All @@ -28,7 +30,7 @@ defineCommand({
requiresArg: true,
},
},
async handler(args) {
async handler(args, { config }) {
if (args.scopesList) {
listScopes();
return;
Expand All @@ -48,7 +50,6 @@ defineCommand({
return;
}
await login({ browser: args.browser });
const config = readConfig(args.config, args, undefined, true);
await metrics.sendMetricsEvent("login user", {
sendMetrics: config.send_metrics,
});
Expand All @@ -66,9 +67,11 @@ defineCommand({
owner: "Workers: Authoring and Testing",
status: "stable",
},
async handler(args) {
behaviour: {
printConfigWarnings: false,
},
async handler(_, { config }) {
await logout();
const config = readConfig(args.config, args, undefined, true);
await metrics.sendMetricsEvent("logout user", {
sendMetrics: config.send_metrics,
});
Expand All @@ -82,16 +85,18 @@ defineCommand({
owner: "Workers: Authoring and Testing",
status: "stable",
},
behaviour: {
printConfigWarnings: false,
},
args: {
account: {
type: "string",
describe:
"Show membership information for the given account (id or name).",
},
},
async handler(args) {
async handler(args, { config }) {
await whoami(args.account);
const config = readConfig(args.config, args, undefined, true);
await metrics.sendMetricsEvent("view accounts", {
sendMetrics: config.send_metrics,
});
Expand Down

0 comments on commit ec6d4cd

Please sign in to comment.